SMTP MIME How do I achieve them

Hi All,

I have an agent which is scheduled to run on a server. The agent shoots out a few mails everyday.

For testing the agent, I run it on my local client. When run on the client, the following code works perfectly. (Thanks to a few posts on the community). The mails are generated in SMTP format.

Call maildoc.ReplaceItemValue(“Form”,“Bookmark”)

Call maildoc.ReplaceItemValue(“Principal”,“Aditya Jois”)

Call maildoc.ReplaceItemValue(“DisplaySent”,“Aditya Jois”)

so, when the user receives the mail, s/he will see the It with the name Aditya Jois in the Inbox and Sent By as Aditya Jois

This is fine, but, when the agent is run on server, the mails generated are in MIME format and all this code is a waste and does not work as intended.

Another problem is that, when I embed a doclink, it works fine in SMTP but not in MIME. So, I came up with this code

If notesag.ServerName <> “” Then

Call rtitem.AppendText(doclink.NotesURL)

Call rtitem.AddNewline(2)

Else

Call rtitem.AppendDocLink(doclink,CurrDB.Title)

End If

i.e. if it is running on a server, I embed the NotesURL else I attach the doclink.

Does anyone have an alternative solution? Any help would be appreciated.

Regards,

Adi

Subject: SMTP MIME How do I achieve them

This might do the trick:

Dim memo As NotesDocument

Dim rtitem As NotesRichTextItem

Dim body As NotesMimeEntity

Dim header As NotesMimeHeader



Set memo = db.CreateDocument

memo.Form = "Memo"			

Set body = memo.CreateMIMEEntity

Set header = body.CreateHeader("From")

Call header.SetHeaderVal("[your from]")

Set header = body.CreateHeader("Reply-To")

Call header.SetHeaderVal("[your reply-to]")

Set header = body.CreateHeader("INetFrom")

Call header.SetHeaderVal("reply <reply@acme.com>")

Call memo.ReplaceItemValue("Subject", "[your subject]")

Set rtitem = memo.CreateRichTextItem("Body")

Call memo.Send(False)

Subject: RE: SMTP MIME How do I achieve them

Hello Rob,

Thank you very much… It works perfectly…

Now that I have achieved part of what I need, how do I achieve this…

The body of the mail is in ‘Default MonoSpace’ font. How do I change it?

I tried

Set richStyle = Ses.CreateRichTextStyle

richStyle.NotesFont = FONT_HELV

Call rtitem.AppendStyle(richStyle)

rtitem is the Body of the mail i.e. Set rtitem = New NotesRichTextItem(maildoc,“Body”)

Thanks again,

Aditya Jois

Subject: RE: SMTP MIME How do I achieve them

It looks like you did the right thing. You inserted this AppendStyle before you actually appended the rest of the body contents? Not all fonts are supported by this function.

Subject: RE: SMTP MIME How do I achieve them

so you mean to say I must insert this appendstyle after I append all the necessary text.

FONT_HELV is a constant so it may most probably be supported… I’ll try and post a response

Subject: RE: SMTP MIME How do I achieve them

Hello Rob,

A new problem… I get this error when I try to set the NotesMIMEEntity for the second time to send another mail to some other user.

Error Number 4485

Error Item Body already exists

What do I need to take care of?

Regards,

Adi

Subject: RE: SMTP MIME How do I achieve them

This line: Set rtitem = memo.CreateRichTextItem(“Body”) is used to create a Body item in your memo. So when that attribute already exists you should skip this line.

Subject: RE: SMTP MIME How do I achieve them

No, I meant that you have to insert the style BEFORE you append the text.

Subject: RE: SMTP MIME How do I achieve them

Hello Rob,

Thank you very much… After reading help I figured out that CreateMIMEEntity by default creates a Body item by default if nothing is mentioned… That is why I was getting the error. Thank you very much for the solution.

The font style is not changing whatsoever. I’ll paste some code and may be you can help.

Dim maildoc As New NotesDocument(CurrDB)

Dim rtitem As NotesRichTextItem

Dim richStyle As NotesRichTextStyle

Set nme = maildoc.CreateMIMEEntity

Set nmh = nme.CreateHeader(“From”)

Call nmh.SetHeaderVal(ckdoc.fmCKCtrlKeywordList(0))

Set nmh = nme.CreateHeader(“Reply-To”)

Call nmh.SetHeaderVal(ckdoc.fmCKCtrlKeywordList(0))

Set nmh = nme.CreateHeader(“INetFrom”)

Call nmh.SetHeaderVal(ckdoc.fmCKCtrlKeywordList(0))

Call maildoc.ReplaceItemValue(“Subject”,“Action”)

Set richStyle = Ses.CreateRichTextStyle

richStyle.NotesFont = FONT_HELV (ANy other font suggestions?)

Set rtitem = New NotesRichTextItem(maildoc,“Body”)

Call rtitem.AppendStyle(richStyle)

Call rtitem.AppendText(“Hello,”)

Call rtitem.AddNewline(2)

Call rtitem.AppendText(“An entry is created for you”)

Call rtitem.AddNewline(2)

Call maildoc.ReplaceItemValue(“SendTo","aditya.jois@abc.com”)

Call maildoc.Send(False)