Hi !
I’ve tried to code an agent to send HTML mails to my customers. But I haven’t found a solution which works for all providers. For example, I had to suppress every chr(13) in the body to see the mails accepted by some providers (free.fr for example) but other providers (banquespopulaires.fr) couldn’t accept the mails because of the length of the line…
So, is there someone who could share a solution ? Here is the function I’ve coded to generate the mail directly in the mail.box :
Function SendHTMLMail(subject As String, body As String, recipients As String, whofrom As String , emailtoreplyto As String)
If (Trim(recipients)<>"") Then
Dim s As New NotesSession
Dim doctosend As NotesDocument
Dim stream As NotesStream
Dim bodyHTML As NotesMIMEEntity
Dim child As NotesMIMEEntity
Dim mailbox As New NotesDatabase("","mail.box")
Set doctosend = mailbox.CreateDocument
doctosend.Form="Memo"
s.ConvertMIME = False ' Do not convert MIME to rich text
Set stream = s.CreateStream
Set bodyHTML = doctosend.CreateMIMEEntity
Set header = bodyHTML.CreateHeader("From")
Call header.SetHeaderVal(whofrom)
Set header = bodyHTML.CreateHeader("SMTPOriginator")
Call header.SetHeaderVal(whofrom)
Set header = bodyHTML.CreateHeader("Sender")
Call header.SetHeaderVal(whofrom)
If emailtoreplyto<>"" Then
Set header = bodyHTML.CreateHeader("ReplyTo")
Call header.SetHeaderVal(emailtoreplyto)
End If
’ body=Replace(body,Chr(13),“”)
’ body=Replace(body,Chr(10),“”)
Set child=bodyHTML.CreateChildEntity
Call stream.WriteText(body)
Call child.SetContentFromText(stream,"text/html;charset=ISO-8859-1",ENC_NONE)
Call stream.Truncate
Call doctosend.ReplaceItemValue("Subject",subject)
Dim recip As New NotesItem(doctosend,"Recipients",recipients,NAMES)
Dim sendTo As New NotesItem(doctosend,"SendTo",recipients,NAMES)
recip.IsSummary=True
sendTo.IsSummary=True
Call doctosend.ReplaceItemValue("PostedDate",Now)
Call doctosend.Save(False,False)
s.ConvertMIME = True ' Restore conversion
End If
End Function
Note that I haven’t used the document.send method because it created some other problems (I had to change the “Run on behalf of” parameter for the mail address of the sender to see the mails accepted by some providers).
Thanks for your help !
Ralph Sicabol