• MailFunctions RFC2156 compliance

    By Martin Kaiser 2 decades ago

    When delivering mail with internet mail protocols (see RFC2156, http://www.rfc-editor.org/rfc/rfc2156.txt), one should add a header that marks an email as auto-generated to prevent mail loops and out of office replies (the same thing as with doc.~$AutoForward = "1").



    Original SendMail Code:

    Function SendMail (md As MailData) As String

    '** create and send an e-mail, based on information in the <br/>
    '** MailData structure that was passed to us<br/>
    On Error Goto mailError<br/>
    <br/>
    Dim session As New NotesSession<br/>
    Dim db As NotesDatabase<br/>
    Dim doc As NotesDocument<br/>
    Dim body As NotesRichTextItem<br/>
    <br/>
    Set db = session.CurrentDatabase<br/>
    Set doc = New NotesDocument(db)<br/>
    Set body = New NotesRichTextItem(doc, &quot;Body&quot;)<br/>
    <br/>
    '** basic mail message stuff<br/>
    doc.Form = &quot;Memo&quot;<br/>
    doc.SendTo = md.sendto<br/>
    doc.CopyTo = md.cc<br/>
    doc.BlindCopyTo = md.bcc<br/>
    doc.Subject = md.subject<br/>
    <br/>
    '** change the apparent sender, if desired<br/>
    If (Len(md.from) &gt; 0) Then<br/>
        doc.Principal = md.from<br/>
    End If<br/>
    <br/>
    '** since we're sending this automatically, we don't want out of office messages<br/>
    doc.~$AutoForward = &quot;1&quot;<br/>
    <br/>
    '** add priority, if desired<br/>
    

    […]



    Suggested Revision:

    Function SendMail (md As MailData) As String

    '** create and send an e-mail, based on information in the <br/>
    '** MailData structure that was passed to us<br/>
    On Error Goto mailError<br/>
    <br/>
    Dim session As New NotesSession<br/>
    Dim db As NotesDatabase<br/>
    Dim doc As NotesDocument<br/>
    Dim body As NotesRichTextItem<br/>
    Dim mime As NotesMimeEntity <br/>
    Dim header As NotesMimeHeader   <br/>
    <br/>
    Set db = session.CurrentDatabase<br/>
    Set doc = New NotesDocument(db)<br/>
    Set body = New NotesRichTextItem(doc, &quot;Body&quot;)<br/>
    Set mime = doc.CreateMIMEEntity <br/>
    <br/>
    '** basic mail message stuff<br/>
    doc.Form = &quot;Memo&quot;<br/>
    doc.SendTo = md.sendto<br/>
    doc.CopyTo = md.cc<br/>
    doc.BlindCopyTo = md.bcc<br/>
    doc.Subject = md.subject<br/>
    <br/>
    '** change the apparent sender, if desired<br/>
    If (Len(md.from) &gt; 0) Then<br/>
        doc.Principal = md.from<br/>
    End If<br/>
    <br/>
    '** since we're sending this automatically, we don't want out of office messages<br/>
    doc.~$AutoForward = &quot;1&quot;<br/>
    Set header = mime.CreateHeader(&quot;autosubmitted&quot;)   <br/>
    Call header.SetHeaderVal(&quot;auto-generated&quot;)<br/>
    <br/>
    '** add priority, if desired<br/>
    

    […]



    —-

    martin