Sending mail via Lotus Notes R5 using VBA

edzigns

New member
Local time
Today, 09:53
Joined
Aug 21, 2002
Messages
22
I have a report that is created for current record, whenever a new record is added, what I want to do is send this report as an attachment or RTF to my Lotus Notes R5 client to about 10 users in my group.....

I can't use the sendobject (and change default mail client in IE as it is disabled), so I need to do it via VB...

Help... I would like this code to work on an onclick command (add_new).... I have the qry and rpt function operable, just need to add the email part of vb.....
 
Found this code a BBS, it works with Lotus Notes 4.5.

Create a module and paste the following code:


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.

'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 <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If

'Send the document
MailDoc.SEND 0, Recipient

'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub


eg.
SendNotesMail "Testl","C:\123.xls","jdoe@abc.com","Hello",True
 
Is there anyway to format the text in the body (bold, different fonts, etc.)? I played around with the RichTextStyle object but couldn't figure out how to get it to work.
 
I just figured this out:

Code:
Dim richStyle As Object

Set richStyle = s.CreateRichTextStyle ' where s represents the notessession object
richStyle.FontSize = 16
richStyle.NotesFont = FONT_HELV
richStyle.Bold = True
richStyle.NotesColor = COLOR_DARK_BLUE
Call rtItem.AppendStyle(richStyle)
 
Does anyone know how to send a lotus notes email to multiple recipients using the previous code.

I can only get it to work with one recipient in each of the To, cc & bcc fields. A comma (,) does not seem to separate recipients.

Thanks
Smed
 
Multiple Addresses

It works in 4.5 using a comma and a space between each address. It should work for you...
 
I'm trying to use this same code to auto send an Excel report located on my network each month (ex. Q:\WWC Common\TAMPA Files\ItemIDCount.xlsx). Where do I put in the file address for the attachment? It’s a bit confusing and I'm just learning VB. Thanks for the help.
 
hello, How can you run this code from a Form..New to Access. :banghead:
 
I'm sure you can write this all in one module, but I wrote my email code in one module then I wrote another module to make a command button on my form automatically run the email code (see command button code below). SendNotesMail is the name of my module, I'm just telling it to run the code on the click. Hope that makes senses, I'm like you and figuring this out as I go. I can post my email code if you feel it will help you, as I did finally figure out how to send it to a distribution list.

Code:
Private Sub EmailItmCt_Click()
 SendNotesMail
End Sub
 

Users who are viewing this thread

Back
Top Bottom