• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Lotus Notes Email Macro

Rob Mulhern

New Member
Hi All,

Please can anyone let me know the code to send an email from Excel using Lotus Notes 9.0?

Is this even possible now?

I have a worksheet which includes dates for certain tasks.
Those dates will be conditionally formatted based on certain criteria. If for example one is flagged Red then I want an automatic email sent out.

Thanks,

Rob
 
I don't have Lotus Notes so I can't test this old code. Change it to suit. You may want to remove the attachment part.

Once you can send, we can help with the loop part.

Code:
Sub test()
  Dim lErr As ErrObject
  SendNotesMail _
    "PMP Handbook5", _
    "c:\t.pdf", _
    "khobson@odot.org,khobson@aaahawk.com", _
    "Click file: " & vbCrLf & _
    "file://u:\Material\pmp\PMP%20Handbook.pdf" & vbCrLf & _
    "or, open the attachement.", , lErr
    If lErr.Number <> 0 Then MsgBox lErr.Number & vbCrLf & lErr.Description
  End Sub

'Escape characters, %20=space, http://everything2.com/node/1350052
'Similar to: Brian Walters, http://www.ozgrid.com/forum/showthread.php?t=67089
Public Sub SendNotesMail(Subject As String, Attachment As String, _
    ByVal Recipient As String, _
    BodyText As String, _
    Optional SaveIt As Boolean = True, _
    Optional ByRef lErr As ErrObject)
    'lErr is used when using the Sub in a batch process,
    'to handle instances where an error appears
   
    'Example of use:
    'SendNotesMail "The Subject", "C:\My Documents\TestFile.txt", _
        "john@doe.com, jane@doe.com", _
        "This is the body text, can be longer", True, lErr
   
  'Set up the objects required for Automation into lotus notes
  Dim Maildb As Object            'The mail database
  Dim UserName As String          'The current users notes name
  Dim MailDoc As Object          'The mail document itself
  Dim AttachME As Object          'The attachment richtextfile object
  Dim Session As Object          'The notes session
  Dim EmbedObj As Object          'The embedded object (Attachment)
  Dim ArRecipients() As String    'Array of recipients
  Dim i As Long                  'Counter
  Dim oBody As Object            'Body of text in for rich text format
 
  'Early Bind - Tools > Reference > Lotus Notes Automation Classes, notes32.tlb
  'Dim ln As lotus.NOTESSESSION
  'Set ln = CreateObject("Notes.NotesSession")
  'Dim db As lotus.NOTESDATABASE
  'Set db = ln.GETDATABASE("", "mail\username.nsf")
  'Dim mDoc As lotus.NOTESDOCUMENT
  'Set mDoc = db.CREATEDOCUMENT
 
 
  'Create an array of recipients (Separated by commas)
  ArRecipients() = Split(Recipient, ",")
 
  'Start a session to notes
  Set Session = CreateObject("Notes.NotesSession")
  On Error GoTo err_h
 
  'Open the mail database in notes
  UserName = Session.UserName
'************** ADD YOUR username.
  Set Maildb = Session.GETDATABASE("", "mail\khobson.nsf")
  If Maildb.IsOpen = False Then
      Maildb.OPENMAIL
  End If
 
  'Set up the new mail document
  Set MailDoc = Maildb.CREATEDOCUMENT
  MailDoc.Form = "Memo"
  MailDoc.sendto = ArRecipients
  MailDoc.Subject = UCase(Subject)
  'MailDoc.Body = UCase(BodyText)
  Set oBody = MailDoc.CREATERICHTEXTITEM("Body")
  oBody.APPENDTEXT BodyText
 
  'This is supposed to be the property, but works
  'on some systems only
  'without an apparent reason of failure
  MailDoc.SAVEMESSAGEONSEND = SaveIt
 
  'Set up the embedded object and attachment and attach it
  If Attachment <> "" Then
      Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
      Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
  End If
 
  'Send the document
  MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
  MailDoc.Send 1
  MailDoc.Save True, True, False
 
  'Clean Up
err_h:
Set lErr = Err
  Set Maildb = Nothing
  Set MailDoc = Nothing
  Set AttachME = Nothing
  Set Session = Nothing
  Set EmbedObj = Nothing
End Sub
 
Back
Top