The following Visual Basic code will send a Notes e-mail message. The code includes examples of code to include an attachment and to save the sent message, which are both optional and can be removed if desired.
Dim Maildb As Object
Dim MailDoc As Object
Dim Body As Object
Dim Session As Object
'Start a session to notes
Set Session = CreateObject("Lotus.NotesSession")
'This line prompts for password of current ID noted in Notes.INI
Call Session.Initialize
'or use below to supply password of the current ID
'Call Session.Initialize("
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", "c:\notes\data\mail\mymail.nsf")
If Not Maildb.IsOpen = True Then
Call Maildb.Open
End If
'Create the mail document
Set MailDoc = Maildb.CREATEDOCUMENT
Call MailDoc.ReplaceItemValue("Form", "Memo")
'Set the recipient
Call MailDoc.ReplaceItemValue("SendTo", "John Doe")
'Set subject
Call MailDoc.ReplaceItemValue("Subject", "Subject Text")
'Create and set the Body content
Set Body = MailDoc.CREATERICHTEXTITEM("Body")
Call Body.APPENDTEXT("Body text here")
'Example to create an attachment (optional)
Call Body.ADDNEWLINE(2)
Call Body.EMBEDOBJECT(1454, "", "C:\filename", "Attachment")
'Example to save the message (optional)
MailDoc.SAVEMESSAGEONSEND = True
'Send the document
'Gets the mail to appear in the Sent items folder
Call MailDoc.ReplaceItemValue("PostedDate", Now())
Call MailDoc.SEND(False)
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set Body = Nothing
Set Session = Nothing
Note: The Visual Basic programmer needs to set the Reference to use Lotus Domino objects prior to implementing this function. To enable the Lotus Notes classes to appear in the Visual Basic browser, you must execute the following within VB: Select Tools, References and select the checkbox for 'Lotus Notes Automation Classes'.
The above code is from the IBM support. GETDATABASE given here is pointing to the sample MailDB; you need to change that to your DB.
You can do that by
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
To send it through Microsoft Outlook refer http://vbadud.blogspot.com/2007/04/vba-email-automation-vba-mail.html
Automate Email, VBA Email, Send Email from Excel, VBA Mail automation, Mail Automation, Lotus Notes VBA, Automate Lotus Notes, Send Mail from Lotus Notes, Link Excel with Lotus Notes,Microsoft Lotus Notes Mail Automation, Excel VBA Mail, MAPI, Send Multiple eMails
Hi!
ReplyDeleteI'd like to know where can I inform the code the exact path of the ID archive and the NSF archive. I can't figure it out...
Thanks in advance!
Its the 12th line
ReplyDeleteSet Maildb = Session.GETDATABASE("", "c:\notes\data\mail\mymail.nsf")
thanks a lot, it's the first one I see working.
ReplyDeletehi... i have a problem where on most of my client's lotus notes, my VBA code is generating html format emails.... but on one client, their lotus Notes seems to be reformatting the borders and replaced it with +-| characters for the borders and completely lost the html formatting...and on their user preferences, it is set to 'html and text' format.
ReplyDeletecan anyone help or suggest anything?
Can someone help with code to capture information of incoming mail using VBA.
ReplyDeleteThanks in advance
Can someone point me to a code which can be used to Reply to a mail in Lotus Notes?
ReplyDeleteHello there,
ReplyDeleteThank you so much for the code. I wonder if you could be so kind as to help me out with one question? How do you code VBA so that it will send you an email when there is new information available?
I am trying to code VBA so that once an automatic system update data on a worksheet, Excel will send me an email to notify me that these data has been updated.
Thank you very much.
Thanx a lot for the code...Really solved my problem
ReplyDeleteHi, I'm struggling to find a way to automate a Lotus Notes email - but instead of creating a new memo each time, I'd like to Stationery I've created.
ReplyDeleteHoping someone out there can help... Thank you!! Amy
Hi,
ReplyDeleteI have an issue in putting the data in lotus notes email through vba excel.
I have to take the content from 3 columns of the mutlitple records in a spreadsheet and put it in the lotus notes provided one of the column satisfies the particular condition. I'm done with this to.
But the spacing between the content of column 1 & column 2 is not even for all records.
For example
Row#1 Text 1 Text 2
Row#2 Text12424 Text989
Row#3 Text38 Text7908
I have tried filling spaces based on column width and used vbtab method. But still the text position of column 2 is not even for all the records. Even though the length of the text in column 1 for multiple records are same, they don't end in the same position because of the different width of the characters.
For example The text "Rakesh LNU" and the text "Saxenabeat" do not end at the same position in column 1 even though they have the same number of characters.
Hope someone can help me out. Thank you!
The code is using late binding as all objects are generic objects and not LOTUS DOMINO objects.
ReplyDeleteSo possibly, it can be run without setting reference to LOTUS DOMINO LIBRARY.
Currently, I am working on building a similar code. And your thread has helped me. So thanks.
Shrivallabha
Can someone help me that how to add recipients in "CC" of mail in above code
ReplyDeleteI wanted to insert an image in the body content of the lotus mail notes.Help me!!
ReplyDeleteHi I found a problem, this works if the mail you are sending is from inside your office, but what if I want to send the email to someone outside my IP and what if I want that mail to change according to a given line
ReplyDeleteI mean if I have a db I want that if the a2 cell has "x" value then the email can be send to the address written in the a14 cell
Is that possible?
Hi i want to add some unique id to all the mails in particuar folder or while replying i have to add unique ids to the subject of all replying mails . is it possible . do you guys have any code for that
ReplyDeleteHow do I amend the code "Call MailDoc.SEND" to rather open the email to allow the user to amend the body text and recipients before send the email
ReplyDeleteI am getting stopped at "If Not Maildb.IsOpen = True Then"
ReplyDeleteany ideas why?
Hi, I want to coding java or .net for create mailbox in Lotus node (domino database). Can you help me the coding?
ReplyDelete