Lotus Notes email attachments

D

Dic_nutana

Hi hope you can help, I am trying to send an email with attachments using
Lotus Notes as the email client.
I have used to code below to send an email with one attachment but I need to
send at least two but as yet I have failed to get it to work, I can only get
it to sent one at a time… can you advise what additional code I need to
attach two or more attachments. I am very much a newbie so any help would be
greatly appreciated
Thanks in advance
Richard

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim Subject As String, Attachment As String, Attachment2 As String,
Recipient As String, BodyText As String, SaveIt As Boolean
'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)


Dim Dir1st As String
Dim strSubPath As String
Dim strFileName As String

Dir1st = "G:\ Lists\Current\"
strSep = "\"
strSubPath = Me.OrganizationName & " (" & Me.id & ")" & strSep

strFileName1 = "2 passed Letter with logo.pdf"
strFileName2 = "1 Cert.pdf"

Recipient = [EmailName]
'bccRecipient =

Attachment = Dir1st & strSubPath & strFileName1
Attachment2 = Dir1st & strSubPath & strFileName2

'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Next line only works with 5.x and above. Replace password with your
password
'Session.Initialize ("password")
'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 or using above password you can use other
mailboxes.
'UserName = Session.rirvine
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.BlindCopyTo = bccRecipient
MailDoc.Subject = "This is a Test email"
MailDoc.Body = "Dear Sir/Madam"

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
MsgBox "E-Mail Sent"
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
 
D

Dic_nutana

Ok now I have got it to do what I needed Thanks anyway

Dic_nutana said:
Hi hope you can help, I am trying to send an email with attachments using
Lotus Notes as the email client.
I have used to code below to send an email with one attachment but I need to
send at least two but as yet I have failed to get it to work, I can only get
it to sent one at a time… can you advise what additional code I need to
attach two or more attachments. I am very much a newbie so any help would be
greatly appreciated
Thanks in advance
Richard

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim Subject As String, Attachment As String, Attachment2 As String,
Recipient As String, BodyText As String, SaveIt As Boolean
'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)


Dim Dir1st As String
Dim strSubPath As String
Dim strFileName As String

Dir1st = "G:\ Lists\Current\"
strSep = "\"
strSubPath = Me.OrganizationName & " (" & Me.id & ")" & strSep

strFileName1 = "2 passed Letter with logo.pdf"
strFileName2 = "1 Cert.pdf"

Recipient = [EmailName]
'bccRecipient =

Attachment = Dir1st & strSubPath & strFileName1
Attachment2 = Dir1st & strSubPath & strFileName2

'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Next line only works with 5.x and above. Replace password with your
password
'Session.Initialize ("password")
'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 or using above password you can use other
mailboxes.
'UserName = Session.rirvine
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.BlindCopyTo = bccRecipient
MailDoc.Subject = "This is a Test email"
MailDoc.Body = "Dear Sir/Madam"

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
MsgBox "E-Mail Sent"
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top