E-Mail URL Wrapping/Truncating and Name Appearance Problem - My Solution

I got really tired of normal Notes e-mail wrap/truncate URL when sending out SMTP mails. I also find it frustrating that the sender name always come up as an e-mail. Before I go further, this subject has been raised before but I did not find a satisfactory solution so I’m hoping my solution will help others. I was looking for a way to control width of message content wrap around. For example, I want to control the width to be 40, or 50, or 60. I think most e-mail package wraps around at 70 characters. However, I don’t want any URL to wrap around such that by the time the message is received the URL is all broken and if you don’t know better to use the copy and paste trick, you can’t get the URL to work. Finally, I wanted to control the appearance of the sender name and whom the reply should go back to if one replies to a message.

This solution is based on my much research, collection of other people’s wisdom, and trial and errors. I apologize if others already have offered similar solutions – I could not find one in the R5 or R6 forum. Basically, the solution is to use MIME to send e-mail and temporary use richtext field’s GetFormattedText( ) to control content width.

Some interesting points to be noted:

  1. Using MIME you can put multiple e-mails in the “To” field delimited by comma so you can send to multiple people. In a non MIME message, you’d need add to a Text list field.

  2. In order to control the appearance of the sender’s name for some reason when I use the CreateHeader( ) and SetHeaderVal( ) functions for the “Principal”, it does not work. I had to use doc.Principal to set the value and do a CreateHeader( ). I can’t just use the doc.Principal to set the value, but I had to tell MIME to create a header. Don’t ask me why this is…I can’t figure out myself. I only got it working after trial-n-error.

  3. You can use Richtext item’s GetFormattedText( ) to control the wrapping of text content. But, don’t use this for the URL. The URL will still be broken/truncated.

  4. In the Principal field I had to add an extra “@mydomain.com” for the sender name to come up right. Otherwise, I get some sort of e-mail address. I’ve tested this against Yahoo, Excite, and Notes e-mails. Maybe others can fill us in if it works for other e-mail systems.

Here is the code

==============================

Sub Click(Source As Button)

Dim session As New NotesSession

Dim db As NotesDatabase	

Dim mailDoc As NotesDocument	

Dim newLine As String

Dim MsgBody As String

Dim MsgBody1, MsgBody2 As String

Dim newMsgBody1, URL, newMsgBody2 As String

Dim tmpBodyItem1, tmpBodyItem2 As NotesRichTextItem

Const MAX_LINE_WIDTH = 60



' init

newLine = Chr(13)

Set db = session.CurrentDatabase

Set mailDoc = db.CreateDocument		' mail doc	



' top part of the letter

MsgBody1 = "Dear John Doe," + newLine + newLine

MsgBody1 = MsgBody1 + "Please indicate whether you are available for the speaker request. "

MsgBody1 = MsgBody1 + "Below are the details of the request:"

MsgBody1 = MsgBody1 + newLine + newLine

MsgBody1 = MsgBody1 + "A speaker request for you has been submitted 3 days ago. "

MsgBody1 = MsgBody1 + "The requesting organization is Test 6. The requesting person is Test, User 6. "

MsgBody1 = MsgBody1 + "The request ID is SBReq114" 

MsgBody1 = MsgBody1 + newLine+newLine

MsgBody1 = MsgBody1 + "Please click on the following URL  for request detail and please indicate your response:"

MsgBody1 = MsgBody1 + newLine + newLine



' construct top portion of the letter and have the content wrapped in 60 char

Set tmpBodyItem1 = mailDoc.CreateRichTextItem( "tmpBody1" )

Call tmpBodyItem1.AppendText( MsgBody1)

newMsgBody1 = tmpBodyItem1.GetFormattedText( False, MAX_LINE_WIDTH )	

Call mailDoc.RemoveItem("tmpBody1")



' below is just an example of a URL that is long and we don't want any wrapping around

URL = "http://www.mydomain.com/MySpeakers.nsf/SpeakerAction?OpenForm&SBReqID=SBReq114&FIELD1=Value1&FIELD2=Value2&FIELD3=Value3"



' bottom part of the letter

MsgBody2 = newLine + newLine + "Regards," + newLine

MsgBody2 = MsgBody2 + newLine

MsgBody2 = MsgBody2 + newLine

MsgBody2 = MsgBody2 + "USA Company" + newLine

MsgBody2 = MsgBody2 + "http://www.mydomain.com" + newLine



' construct bottom portion of the letter and have the content wrapped in 60 char

Set tmpBodyItem2 = mailDoc.CreateRichTextItem( "tmpBody2" )

Call tmpBodyItem2.AppendText( MsgBody2)

newMsgBody2 = tmpBodyItem2.GetFormattedText( False, MAX_LINE_WIDTH )	

Call mailDoc.RemoveItem("tmpBody2")



MsgBody = newMsgBody1+ URL + newMsgBody2	



' "Speakers Request" is what's will be appear as the sender's name

' I learned from another post that you have to put an extra mydomain.com

' for the name to show up right

mailDoc.Principal = |"Speaker Request"<info@mydoamin.com@mydomain.com>|

mailDoc.ReplyTo = "info@mydoamin.com"



' try send it as MIME mail	

Dim body As NotesMIMEEntity

Dim header As NotesMIMEHeader

Dim stream As NotesStream

Set stream = session.CreateStream

session.ConvertMIME = False ' Do not convert MIME to rich text	

Set body = mailDoc.CreateMIMEEntity



' for some reason if I don't create a MIME header, Principal does not work

' even if I use the SetHeaderVal

Set header = body.CreateHeader("Principal")



Set header = body.CreateHeader("Subject")	

Call header.SetHeaderVal("Speaker Request: Please indicate your response for a speaker request")



Set header = body.CreateHeader("To")

Call header.SetHeaderVal("johndoe@companyb.com, janedoe@companyc.com, joeblow@companyc.com")



Call stream.WriteText( MsgBody )

Call body.SetContentFromText (stream, "text/plain;charset=UTF-8", ENC_NONE)  

Call mailDoc.Send(False)

session.ConvertMIME = True ' Restore conversion

End Sub

==============================