Monday, January 04, 2010

How to send email with Lotus Notes

It is pretty easy if you have VBA routine. Link from IBM site will give you one. And here one from my application:

Public Function SendNotesMail(strTo As String, _
    strSubject As String, strBody As String, _
    strFileName As String, ParamArray strFiles()) As Boolean
    'Usage:
    'SendNotesMail "SteveO@microsoft.com", _
        "subj", "some body", "c:\filename.txt"
 
    Dim doc As Object   'Lotus NOtes Document
    Dim rtitem As Object '
    Dim Body2 As Object
    Dim ws As Object    'Lotus Notes Workspace
    Dim oSess As Object 'Lotus Notes Session
    Dim oDB As Object   'Lotus Notes Database
    Dim X As Integer    'Counter
 
    Set oSess = CreateObject("Notes.NotesSession")
    'access the logged on users mailbox
    Set oDB = oSess.GETDATABASE("", "")
    Call oDB.OPENMAIL
 
    'create a new document as add text
    Set doc = oDB.CREATEDOCUMENT
    Set rtitem = doc.CREATERICHTEXTITEM("Body")
    doc.sendto = strTo
    'doc.CopyTo = CCToAdr
    'doc.BlindCopyTo = BCCToAdr
    doc.Subject = strSubject
    doc.Body = strBody & vbCrLf & vbCrLf
 
    'attach files
    If strFileName <> "" Then
        Set Body2 = rtitem.EMBEDOBJECT(1454, "", strFileName)
        If UBound(strFiles) > -1 Then
            For X = 0 To UBound(strFiles)
                Set Body2 = rtitem.EMBEDOBJECT(1454, "", strFiles(X))
            Next X
        End If
    End If
    doc.SAVEMESSAGEONSEND = True
    doc.SEND False
 
    SendNotesMail = True
End Function
 
 
 
 

9 comments:

  1. hi Alex,

    it seems awesome. Is there any possibikity to do the same for
    Outlook.

    regards,
    Roopesh

    ReplyDelete
  2. Hi,
    there are plenty of samples, see:
    http://support.microsoft.com/kb/209948

    and for advanced: http://www.outlookcode.com/

    ReplyDelete
  3. Anonymous12:39 PM

    Hi Alex,

    Thank you very much!
    I need to send 500 different emails and 500 different attachments. Is there a way to do this?

    ReplyDelete
  4. yes, you can send 500 emails using this method

    ReplyDelete
  5. Great help to send bulk emails using Lotus Notes. It seems me the right place to share that Lotus Notes save all our data in NSF file. This NSF file sometimes gets corrupt or becomes inaccessible due to various reasons. But IBM provides no tool that helps us in recovering NSF file so we have to rely on third party nsf file recovery tools.

    ReplyDelete
  6. Anonymous8:53 AM

    Where can I use this code, sorry i am a newbie.

    ReplyDelete
  7. Anonymous2:37 AM

    I've tried strings, arrays but I can't get the Public Function SendNotesMail to cc more than two people at one time. I've tried these for cc:
    array("email1@some.com","email2@some.com","email3@some.com")
    and
    "email1@some.com","email2@some.com","email3@some.com"
    Best I got are the first two get sent. What's up?

    ReplyDelete
  8. try this:

    SendNotesMail("email1@some.com;email2@some.com","Subject"...

    ReplyDelete
  9. NSF Repair Kit
    A must-have Lotus Notes NSF repair utility for home users and professionals dealing with NSF file corruption on a regular basis.

    As it works, is described here: http://www.nsf.repair/

    If it doesn't work, then look here: http://www.filerepairforum.com/forum/other/other-aa/lotus-notes/357-how-to-repair-corrupted-nsf-file-in-lotus-notes

    ReplyDelete