Rich text not preserved when using LotusScript(Send) or @Mailsend

This issue was raised a couple years back but yielded no solution or explanation:http://www-10.lotus.com/ldd/nd8forum.nsf/DateAllThreadedWeb/386b26f52669394d852579f10064f925?OpenDocument

I’m expanding the original question because the issue is broader than described and affects versions 5, 6, 7 & 8.

To reproduce:

1.) Create an email with rich text formatting in body.

2.) Save as Draft

3.) Open email from Draft Folder

4.) Click Send

→ Email will be sent with rich text formatting preserved as expected.

BUT – use LotusScript(Send), @Mailsend - with or without parameters - to send the same document and the formatting is stripped from the email.

The same behavior occurs when re-sending an email from the sent folder (or anywhere else, for that matter). The Send Button will send the email with rich text preserved, while any of the other methods result in a plain-text email.


Our ultimate goal is to use an Agent to send (or resend) an email for a variety of reasons… and we have all the desired functionality EXCEPT the ability to send rich text in the body field.

Subject: Rich text not preserved when using LotusScript(Send) or @Mailsend

I do this without issue. There has to be something else going on that you aren’t pointing out.

This simple function should do it.

Function SendDocumentasEmail (doc As NotesDocument) As boolean

Dim session As New NotesSession

Dim mailservername As String

Dim mailbox As NotesDatabase

Dim maildoc As notesdocument

Dim rtitemSource As NotesRichTextItem

Dim rtitemTarget As NotesRichTextItem



SendDocumentasEmail = False 'set default return state to false



mailservername = session.Currentdatabase.Server

' Using mail.box directly is unsupported, but is the

' only way to make the mail look like it is actually

' sent from another address, in our case the principal.

Set mailbox = New NotesDatabase(mailservername,"mail.box")

If mailbox.Isopen = False Then

	Print "mail.box on " & mailservername & " could not be opened"

	Exit Function

End If





If Not (doc Is Nothing) Then

	Set maildoc = New NotesDocument(mailbox) ' Create New document in mail.box

	'Call doc.CopyAllItems( maildoc, True ) 'Copy the document to mail.box	

Else

	Print "No document was passed to SendDocumentAsMail"

	Exit Function

End If



Call maildoc.ReplaceItemValue("Form","Memo")

Call maildoc.ReplaceItemValue("Subject","This is the subject")

Call maildoc.ReplaceItemValue("SendTo","user@widgets.com")

Call maildoc.ReplaceItemValue("Recipients","user@widgets.com")



Call maildoc.ReplaceItemValue("Principal", "Carl Tyler/ACME")

' We want it so mail looks like it is coming from that address, need to set these fields

Call maildoc.ReplaceItemValue("From", "Carl Tyler/ACME")

Call maildoc.ReplaceItemValue("SMTPOriginator", "ctyler@acme.com")





Set rtitemTarget = New NotesRichTextItem(maildoc, "Body" )

Set rtitemSource = maildoc.GetFirstItem("Body")

Call rtitemTarget.AppendRTItem( rtitemSource )

Call rtitemSource.Remove





Call maildoc.Save( True, True )

SendDocumentasEmail=True

Exit Function

ErrorHandler:

Print Error$ + " --- Line in SendDocumentssEmail: " + Str$(Erl)

Exit Function

End Function

Subject: RE: Rich text not preserved when using LotusScript(Send) or @Mailsend

Carl:

I dropped your script into an Agent and it executes reliably. Thanks for passing that along.

While the contents of the Rich Text field do get copied, however, once the email gets to the recipient, any formatting is removed – the message essentially arrives as Plain Text with the original in-line images stripped and added as attachments.

This has been my challenge all along.

Opening an existing email, whether from Sent or Drafts, and clicking the “Send” button, sends the email while preserving all RT formatting, including in-line images.

Any other method of sending (a draft), re-sending (from Sent), or copying-and-resending (as in your code), results in stripped formatting.

I want to add that the issue exists whether sent out via SMTP.BOX (my desired functionality) or via MAIL.BOX.

Subject: You have something else going on.

I run that script here and the RichText field maintains 100% fidelity.

Subject: Investigate “Specifying inbound and outbound MIME conversion options”

Check them in the server config as I think you will find that is your problem and not the code.

Subject: SOLVED: “Store contents as HTML and MIME” checkbox in Body field property

Thanks so much, Carl.

Your code helped because it gave me a fresh perspective, allowing me to look beyond code for the solution.

Turns out there’s this lonely little checkbox on the Control tab inside the Body field properties for the Memo document:

“Store contents as HTML and MIME” and it was unchecked.

Checked the box and all my troubles went away. My agents are now humming away, dutifully sending out rich text emails right on schedule.

Subject: RE: Rich text not preserved when using LotusScript(Send) or @Mailsend

Much appreciated, Carl.

I like your approach to forcing a particular “SentBy”… we accomplished this with switching user IDs, but your method is much, much cleaner!

For testing purposes, can I safely drop the code into an Agent that I run manually from the Action Menu and have it process the currently selected document (email)?

Michael