Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sendmail in VBA to Lotus Notes

Status
Not open for further replies.

marksnow

Programmer
Oct 30, 2002
39
AU
Hi everyone

I have been successfully in getting some code to work that basically sends an email through lotus notes and saves a copy of the email in the sent items folder.

My problem is that I want some code that will basically open up a new email and insert the email address, subject and attached a file. I don't want it to send automatically. At this stage I need the user to type in any information to the email and have the option to attach further files.
I have tried just removing the send mail code but then it basically does nothing.

Anyone know how I can get Lotus Notes to open a new email with the above from VBA?

Cheers
Mark
 
Okay further to this I have found that the sendobject seems to do what I want.

Another question I have is that I want it to attached a PDF file to the email, not a report, form, table ect. Can this be done and how?
 
To Mark,

I don't know how to solve your problem unfortunately, as I have only ever run the Notes code invisibly in the background to send automatically. However you may be able to help me with something! How do you get the code to save a copy of the E-Mail in the Sent items folder?
 
I found some code on a website that seems to be working well for me. Please see below. The code below makes sure the person is logged into lotus notes and also saves a copy of the email in the sent items folder.

And to anyone else do you know how to attach a file using the sendobject apart from a report etc. (wanting to attach pdf file)




'Public Sub SendNotesMail(Subject as string, attachment as string,
'recipient as string, bodytext as string,saveit as Boolean)
'This public sub will send a mail and attachment if neccessary to the
'recipient including the body text.
'Requires that notes client is installed on the system.

Public sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, BodyText As String, SaveIt As Boolean)
'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 MailDbName As String 'THe current users notes mail database 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)
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
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)
If Maildb.ISOPEN = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.body = BodyText
MailDoc.SAVEMESSAGEONSEND = SaveIt
'Set up the embedded object and attachment and attach it
If Attachment <> &quot;&quot; Then
Set AttachME = MailDoc.CREATERICHTEXTITEM(&quot;Attachment&quot;)
Set EmbedObj = AttachME.EMBEDOBJECT(1454, &quot;&quot;, Attachment, &quot;Attachment&quot;)
MailDoc.CREATERICHTEXTITEM (&quot;Attachment&quot;)
End If
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.SEND 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End sub
 
Hi Mark,

I have a small msaccess application running, where I generate a .pdf file, based on a msaccess offer report. The .pdf file is used to send as attachment on a lotus notes mail to selected customer(s).

I don't know if you already found a solution, but if you are still interested I can post the vba code if I find some time.

regards

jclaus
 
jclaus,

Can you please post your code.

DH
 
Hi DH,

this code is only slightly different compared to the marksnow version, so we may have used the same source. We use it for several months by now to create and send reports in .pdf format to different people with a single button click.

Option Explicit

'Declare public object variables
Public mkfDoc As String
Public Subject, Attachment, Recipient, copyto, BodyText, UserName, SaveIt

Public Maildb As Object 'The mail database
Public MailDbName As String 'The current users notes mail database name
Public MailDoc As Object 'The mail document itself
Public AttachME As Object 'The attachment richtextfile object
Public Session As Object 'The notes session
Public EmbedObj As Object 'The embedded object (Attachment)


Public Function sendNotes()
'Set up the objects required for Automation into lotus notes
Subject = "Your Subject Title"
Attachment = "c:\foldername\filename.extension"
Recipient = "addresseename@organisation.com"
'Set bodytext for mail offer - language depends on field in offprofrm
BodyText = "Your bodytext - This report can be opened with Acrobat Reader"
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.ISOPEN = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.body = BodyText
MailDoc.SAVEMESSAGEONSEND = True
'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")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document + notify
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.SEND 0, Recipient
MsgBox "Mail was sent to " & Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Function

regards
johny claus

 
What's the best way to send to more than one recipient?

Thanks!
 
Is it possible to copy and paste the data from the attachment into the body of the email instead of attaching the document?

Or can you do a print screen of the file and paste in the body of the email?

My boss does not want an excel attachment because some lotus notes users do not have excel.

Any ideas what the code would be to do this?
 
I just wanted to thank everybody for the code postings on this thread. I've been trying to figure out how to email Notes emails through access for awhile now. The code on this thread will enable me to move forward with my project, so kudos to everybody! Thanks so much!

jender624
 
Anybody know how to add a CC and/or flag the email as high importance?

Thanks!
Ryan
 
For anyone who cares, you can also carbon copy another person with CopyTo:

'Using above code snippet...
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.CopyTo = RecipientOther
MailDoc.Subject = Subject
MailDoc.body = BodyText
MailDoc.SAVEMESSAGEONSEND = True

I was told that MailDoc.Importance = 1 would flag the document as important, as well.

Rgds,
Ryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top