Home > Lotus Notes, Quickr > Sending an email with a custom “sender” with Lotus Notes/Domino

Sending an email with a custom “sender” with Lotus Notes/Domino

August 17th, 2009 Leave a comment Go to comments
Share

I recently had the need to send an email from a Notes application where the sender wasn’t going to be me, nor the agen’t signer.   I tried many methods I’d found on the forums, on the many articles, on help from twitter, and finally, by opening a PMR with Lotus support, only to be told that IBM/Lotus won’t help me because it is spoofing.

I am not spoofing anything. I have a legitimate business need to send out emails, where there is no mention of the user performing the action, nor the signer of an agent, nor the server’s id either.

If I set the mail document’s fields, nothing should be changing them.

e.g.
Dim mysender As String, mysenderN As String
mysender = "emaillistedinNAB@myinetdomain.com"
mysenderN = mysender & "@NotesDomain" 'Needed for internal routing only
maildoc.From = mysenderN
maildoc.SMTPOriginator = mysender
maildoc.Sender = mysender
maildoc.Principal = mysenderN
maildoc.INETFROM = mysender
...
maildoc.send (true,false)

If I stop the router, and look at the document in the mail.box, the INETFROM shouldn’t be different, but it is, and it is my email address, well, the address associated with my .id file.

I see far too many posts and things about this in the forums.  I’ve looked and looked, but couldn’t spot how to accomplish this.  Well, I finally read it somewhere, and I can’t remember where, but put simply, if you are working in the mail.box, don’t use the “send” method, simply use the “save” method, and voilà, the mail will leave how you programmed it.

This is my example code for sending a MIME email, with a “spoofed” sender using Lotus Notes/Domino 8.5. Is it perfect – no, but it does work for me…

Dim s As New NotesSession Dim Subject As String, SendTo As String Dim Sender As String, SenderN As String 'the address you want the mail to appear to be from Sender = "FName LName <flname@domain.com>" SenderN = "FName LName <flname@domain.com@NotesDomain>" 'Alternatively, you could just use: 'Sender = "flname@domain.com" 'SenderN = Sender & "@NotesDomain" subject = "This is the subject line" SendTo = "someone@somedomain.com" Dim DBmbox As New NotesDatabase("servername", "mail.box") Dim mail As New NotesDocument( DBmbox ) s.ConvertMIME = False ' Do not convert MIME to rich text Dim body As NotesMIMEEntity Dim header As NotesMIMEHeader Dim stream As NotesStream Dim child As NotesMIMEEntity Set stream = s.CreateStream Set body = mail.CreateMIMEEntity Set header = body.CreateHeader({MIME-Version}) Call header.SetHeaderVal("1.0") Set header = body.CreateHeader("Content-Type") Call header.SetHeaderValAndParams({multipart/alternative;boundary="=NextPart_="}) 'Add the to field Set header = body.CreateHeader("To") Call header.SetHeaderVal(SendTo) 'Add Subject Line Set header = body.CreateHeader("Subject") Call header.SetHeaderVal(subject) 'Add the body of the message Set child = body.CreateChildEntity Call stream.WriteText("<p>") Call stream.WriteText("<font face=Verdana color=#0288C1 size=3>") Call stream.WriteText(|<div class="headerlogo">|) 'If you are referencing any external files, images, javascript, you must use a fully qualified URL/Path Call stream.WriteText (|<img src="http://yourserver.com/images/somelogo.gif" alt="SomeLogo">|) Call stream.WriteText(|</div></font>|) Call stream.WriteText(|...some more HTML |) Call child.setContentFromText(stream, {text/html;charset="iso-8859-1"}, ENC_NONE) Call stream.Truncate 'Not sure if I need this Call stream.Close Call mail.CloseMIMEEntities(True) Call mail.replaceItemValue("Form", "Memo") Call mail.replaceItemValue("Recipients", SendTo) Call mail.replaceItemValue( "From", SenderN ) Call mail.replaceItemValue( "InetFrom", Sender ) 'Since we created the mail in the mail.box, we just need to save it, not send it! Call mail.Save(True,False) s.ConvertMIME = True ' Restore conversion
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.

Similar Posts:

Share
  • murraycroft

    Hi Joseph — I have been struggling to get a MIME email code to work and finally — with some modification you example above is working — thanks. I had tried the IBM example code but that was failing — the send to being converted as <murraycroft@oakmont.co.uk> rather than murraycroft@oakmont.co.uk and our Domino SMTP failed.
    Couple problems I am having with you example code.

    1. The “from As String” errors when compiled in Lotusscript. My workaround was to remove the from variables and enter the values directly in the Call Replace Item values.

    2. I can't seem to get the header logo to work. What is the correct path to be used. I had expected “/icons/XYZ.gif” with this being the data/domino/icons folder on the server. ?? What am I missing here as this would be a nice touch.

    Finally — build = Domino 8.0.2, using your example code in a WebQuerySave called agent to send out email alerts in an Project Issues log.

    All the best

    Murray

  • Sorry about that – will fix the code. “From” is a reserved word, and in my haste to ambiguate the code a bit, I used it.

    If you change it to sender or just about anything else, it should work.

    I change the code above from this:

    Dim from As String
    'the address you want the mail to appear to be from
    from = “FirstName LastName <firstnamelastname@mydomain.com>”

    Call mail.replaceItemValue(“From”, from )
    Call mail.replaceItemValue(“InetFrom”, from )

    to:

    Dim Sender As String, SenderN As String
    Sender = “FName LName <flname@domain.com>”
    SenderN = “FName LName <flname@domain.com@NotesDomain>”
    Call mail.replaceItemValue( “From”, SenderN )
    Call mail.replaceItemValue( “InetFrom”, Sender )

    As for the “icons” issue, you need to use a fully qualified path to it, since this is an email, not a webpage, it has no relative paths. Again, I'll update the code and comment it, but for now you need to use something like:
    <img src=”http://yourserver.com/icons/logo.gif”>

    Or, since I don't like to use the “stock” Domino directories for stuff like this, I simply have an “images” directory under my datadominohtml folder and then I use paths like:
    <img src=”http://yourserver.com/images/logo.gif”>

    Glad you were able to make use of this!

  • murraycroft

    Hi Joseph — I have been struggling to get a MIME email code to work and finally — with some modification you example above is working — thanks. I had tried the IBM example code but that was failing — the send to being converted as <murraycroft@oakmont.co.uk> rather than murraycroft@oakmont.co.uk and our Domino SMTP failed.
    Couple problems I am having with you example code.

    1. The “from As String” errors when compiled in Lotusscript. My workaround was to remove the from variables and enter the values directly in the Call Replace Item values.

    2. I can't seem to get the header logo to work. What is the correct path to be used. I had expected “/icons/XYZ.gif” with this being the data/domino/icons folder on the server. ?? What am I missing here as this would be a nice touch.

    Finally — build = Domino 8.0.2, using your example code in a WebQuerySave called agent to send out email alerts in an Project Issues log.

    All the best

    Murray

  • Sorry about that – will fix the code. “From” is a reserved word, and in my haste to ambiguate the code a bit, I used it.

    If you change it to sender or just about anything else, it should work.

    I change the code above from this:

    Dim from As String
    'the address you want the mail to appear to be from
    from = “FirstName LastName <firstnamelastname@mydomain.com>”

    Call mail.replaceItemValue(“From”, from )
    Call mail.replaceItemValue(“InetFrom”, from )

    to:

    Dim Sender As String, SenderN As String
    Sender = “FName LName <flname@domain.com>”
    SenderN = “FName LName <flname@domain.com@NotesDomain>”
    Call mail.replaceItemValue( “From”, SenderN )
    Call mail.replaceItemValue( “InetFrom”, Sender )

    As for the “icons” issue, you need to use a fully qualified path to it, since this is an email, not a webpage, it has no relative paths. Again, I'll update the code and comment it, but for now you need to use something like:
    <img src=”http://yourserver.com/icons/logo.gif”>

    Or, since I don't like to use the “stock” Domino directories for stuff like this, I simply have an “images” directory under my datadominohtml folder and then I use paths like:
    <img src=”http://yourserver.com/images/logo.gif”>

    Glad you were able to make use of this!

  • Kris Mitchell

    What is the @NotesDomain at the end of the SenderN used for?

    Does the mail get removed from the mail box once it's saved and picked up by the router?

    Nice work! I've been looking for this (or another solution) for a while.

  • The @NotesDomain lets the router know the address is an internal one. Similar to using CN/OU/O format, but in “internet address” style.

    Yes, once you save it in the mail.box, the router treats it just as if a mail arrived into the box through “normal” means”

    Thanks – glad it could help!

  • Guru

    Great Work. How to add a notes document attachment. I tried and I was not able to accomplish this. It is Ok for me if it does not display in HTML. I want it in notes

    Guru

  • I’m not sure if you mean that you just want a link to a notes document, in the typical fashion, or, you want the document as an actual attachment as it’s contents.If you just want a link to the Notes document, get a handle to the notes document you want to attach, and get the doc id and replica id of the database it is stored in, and create an anchor tag “a href= to a notes:// style link The format is:notes://servername/db/view/docwhere db can be either the Replica ID (HIGHLY RECOMMENDED!) or the actual filepath/name; view and doc can be either the real names or aliases or UNID, which can all be obtained by parsing however you are getting a handle to the NotesDocument.Or, you can attachment any kind of document to a MIME mail by adding in a child entity (CreateChildEntity()) to the main body, set the header to a content-type with a value of mulitpart/mixed, set a content-disposition to attachment;yourfilename, set a content-ID to the same, create a stream, pull in that file as binary, in the child, do a SetContentFromBytes of that stream, setting the correct mime type – e.g. application/pdf or image/gif,close the stream and put all this before you fire off the final send. Hopefully that sets you on the right path, if not, have a look in the v6 forums – http://www-10.lotus.com/ldd/nd6forum.nsf/Search?SearchView&Query=n%3Ftes%3A//&SearchOrder=0&Start=1&Count=100 for the notes:// stuff, or search for mime types, and/or content disposition and ENC_IDENTITY_BINARY.