PDA

View Full Version : Solved: Help on how VBA could attach file to Lotus Notes Email template and save to drafts



fgm1215
07-23-2008, 01:30 AM
Hi All,

Does anyone knows how to attach a file into an email template of lotus notes and save to drafts folder without sending it?

Need help :help

Thanks,

Poundland
08-15-2008, 03:46 AM
Hi All,

Does anyone knows how to attach a file into an email template of lotus notes and save to drafts folder without sending it?

Need help :help

Thanks,

Hi,

This code will allow you to attach a file to a Lotus Notes email and send it, you are welcome to try and modify it so it only saves as draft and does not send.

Sub email()
Dim noSession As Object, noDatabase As Object, noDocument As Object
Dim obAttachment As Object, EmbedObject As Object
Dim stSubject As Variant
Dim stAttachment As String

Dim vaRecipient As Variant, vaMsg As Variant

Const EMBED_ATTACHMENT As Long = 1454

' Starts the For Next loop to assign variable email target
For e = 1 To 3
If e = 1 Then vaRecipient = "scott.atkinson@poundland.co.uk"
If e = 2 Then vaRecipient = "neil.maher@poundland.co.uk"
If e = 3 Then vaRecipient = "helen.allsop@poundland.co.uk"
On Error GoTo SendMailError

vaMsg = "THIS AN AUTOMATED EMAIL ----- " ' Put your Body text here
stSubject = "*** Essentials Availability Report ***" ' Put your subject text here

stAttachment = "I:\H925 Buying\Scott Atkinson\Projects\Helen's Availability Project\Essentials Availability.xls" ' Define your attached file here

'Instantiate the Lotus Notes COM's Objects.
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", "")
'If Lotus Notes is not open then open the mail-part of it.
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
'Create the e-mail and the attachment.
Set noDocument = noDatabase.CreateDocument
Set obAttachment = noDocument.CreateRichTextItem("stAttachment")
Set EmbedObject = obAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)
'Add values to the created e-mail main properties.
With noDocument
.Form = "Memo"
.SendTo = vaRecipient
.Subject = stSubject
.Body = vaMsg
.SaveMessageOnSend = True
End With
'Send the e-mail.
With noDocument
.PostedDate = Now()
.Send 0, vaRecipient
End With

Next e
GoTo line1

SendMailError:
Dim Msg
Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
'SendMail = False
line1:
End Sub

tca_VB
08-15-2008, 05:18 AM
Try following some of the code in this link, it should get you pretty close:

http://www.ozgrid.com/forum/showthread.php?t=18259

klukiyan
05-22-2013, 09:28 AM
thank you,
works like a charm even with team mailboxes after slight editing