Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sending Mail through Lotus Notes from Excel using VBA

14 views
Skip to first unread message

Dom

unread,
Jan 29, 2002, 2:51:53 PM1/29/02
to
Is it possible, are there commands in VBA, which allow mail to be sent
through Lotus Notes???

If so, hints as to possible coding would be greatly appreciated

DG


Wilson

unread,
Jan 29, 2002, 3:12:51 PM1/29/02
to
I highly recommend this Public Domain Windows console utility that sends the
contents of a file in an e-mail mesage using the SMTP protocol. I use it to
send over 100 e-mails via Lotus Notes every month.
http://www.vrdom.com/Howto/Blat1_8_2.htm
HTH?

"Dom" <do...@dojy.fsnet.co.uk> wrote in message
news:a36un0$pq6$1...@newsg1.svr.pol.co.uk...

Jeff McAhren

unread,
Jan 29, 2002, 3:20:11 PM1/29/02
to
Hi Dom,

Here is some code that I snagged off of this board last year. I have never
tried it.


Sub testSendMail()
Dim bOK As Boolean
bOK = sendNotesMail(Range("Subject"), Range("Attachment"),
Range("Recipient"), Range("BodyText"), Range("SaveIt"))
MsgBox "sent: " & CStr(bOK)
End Sub

Function sendNotesMail(Subject As String, attachment As String, recipient As
String, bodytext As String, SaveIt As Boolean) As Boolean
Dim Maildb As Object
Dim UserName As String
Dim MailDbName As String
Dim MailDoc As Object
Dim AttachME As Object
Dim session As Object
Dim EmbedObj As Object

On Error GoTo err_SendNotesMail

'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 = Mid$(UserName, 4, 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 <> "" And Dir(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
Maildb.Close
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set session = Nothing
Set EmbedObj = Nothing
sendNotesMail = True

end_SendNotesMail:
Exit Function

err_SendNotesMail:
Select Case Err.Number
Case 429:
MsgBox "Error: " & vbCrLf & Err.Description & vbCrLf & "Possible
cause:" & vbCrLf & "Lotus Notes not installed", vbCritical, "Error
whileinitializing LotusNotes"
Case Else:
MsgBox Err.Description & Err.Number, vbCritical, "Error Lotus Notes
Mail"
End Select
Resume end_SendNotesMail
End Function

Sub SendLotusNote()

' be sure to reference the Lotus Domino Objects, domobj.tlb
Dim objNotesSession As Object
Dim objNotesDatabase As Object
Dim objNotesDocument As Object
Dim objAttachment As Object
Dim objRichText As Object
Dim FullPath As String
Dim FileName As String
Dim Msg As String

Const EMBED_ATTACHMENT = 1454

Set objNotesSession = CreateObject("Notes.Notessession")
Set objNotesDatabase = objNotesSession.GETDATABASE("", "")
Call objNotesDatabase.OpenMail default mail database
If objNotesDatabase.IsOpen = False Then
MsgBox "Cannot connect to Lotus Notes."
Exit Sub
End If
Set objNotesDocument = objNotesDatabase.CreateDocument
Call objNotesDocument.ReplaceItemValue("Form", "Memo")

Do ' prompt user for file name and location
FullPath = Application.GetSaveAsFilename
Loop Until FullPath <> False
' save to new loc; Lotus only sends last-saved copy
ActiveWorkbook.SaveAs FullPath
FileName = ActiveWorkbook.Name

' assemble message
Set objRichText = objNotesDocument.CreateRichTextItem("Body")
Set objAttachment = objRichText.EmbedObject(EMBED_ATTACHMENT, "",
FullPath, FileName)
Msg = "Lotus Note sent from " & objNotesSession.CommonUserName
With objNotesDocument
.Subject = "Excel Lotus Note!"
.Body = Msg
.sendTo = "lotus.mailbox"
.SaveMessageOnSend = True ' save in Sent folder
.Send (False)
End With

Set objNotesSession = Nothing
Set objNotesDatabase = Nothing
Set objNotesDocument = Nothing
Set objAttachment = Nothing
Set objRichText = Nothing

MsgBox "Your Lotus Notes message was successfully sent"
ActiveWorkbook.Close

End Sub

Sub EMail()
'You will also need to reference 'Notes32.tlb' in your project.
Dim session As Object
Dim db As Object
Dim doc As Object

Set session = CreateObject("Notes.NotesSession")
Set db = session.GETDATABASE("Your Domino Server", "Your Mail Database")
Set doc = db.CreateDocument()
doc.Form = "Memo"
doc.Subject = "VB App Test " & Now()
doc.Body = "VB App Test. Sending Notes memos via VB"
doc.sendTo = "y...@yourcompany.com"
Call doc.Send(False, "")


Set doc = Nothing
Set db = Nothing
Set session = Nothing
End Sub

Sub mailsend2()
Dim Data As Variant
Dim mailcount As Integer
Dim s As Object, db As Object, doc As Object

Data = Range("A1:B6").Value 'defines the source data in two cols on
active sheet

Set s = CreateObject("Notes.NotesSession")
Set db = s.GETDATABASE("", "mail\username.nsf")
Set doc = db.CreateDocument()

For mailcount = 1 To 6

doc.Form = "Memo"
doc.sendTo = Data(mailcount, 1)
doc.Subject = Data(Str(mailcount), 2)
doc.Body = "Rats Trousers" & " " & Data(Str(mailcount), 2)
Call doc.Send(False)

Next

Set s = Nothing
Set db = Nothing
Set doc = Nothing

End Sub


--
Jeff McAhren
Dallas, Texas


"Dom" <do...@dojy.fsnet.co.uk> wrote in message
news:a36un0$pq6$1...@newsg1.svr.pol.co.uk...

0 new messages