Search This Blog

Thursday, July 21, 2016

Avoid processing items as both NotesItem and NotesMIMEEntity objects concurrently.

Hi guys

May be this will save a day to someone.

Let's imagine you need to send email with HTML inside.
In most of cases you would need to use NotesMIMEEntity class and probably some other MIME-related classes to build mail Body. Though it is possible to use the same classes to define Subject, SendTo, CopyTo and other mail headers people often use usual NotesItem-based syntax for the rest simple mail parameters.

However very important point is that as soon as you used NotesMIME-class you can NOT use NotesItem-based syntax until you close all NotesMIME entities.

So, if you write something like below, it will be rather OK

....
Set mailDoc = db.createdocument
mailDoc.Subject ="blablabla"
mailDoc.SendTo ="test@gmail.com"

Set mime = mailDoc.CreateMIMEEntity()
.......
call maiDoc.send(false)

However, if you do it in another order you will reap problems sooner or later

....
Set mailDoc = db.createdocument
Set mime = mailDoc.CreateMIMEEntity()
.......
mailDoc.Subject ="blablabla"
mailDoc.SendTo ="test@gmail.com"
call maiDoc.send(false)

The last example can even work when you try it, but then after some time users may complain about empty mail Body or something else.

If you really need to work with mail NotesItems after you used NotesMIME-classes you have to close all MIME entities first, for example, using method NotesDocument.CloseMIMEEntities.

Actually, everything I said here you can find in description of NotesMIMEEntity class in Usage part that I personally read not carefully enough.

No comments:

Post a Comment