FORUM PLAN UPDATE: Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.
Marcel Muller 24.Oct.16 05:33 AM a Web browser Notes Client All Releases All Platforms
I have the following VBA macro to automate sending emails, but the issue I have is that a mail is held in outgoing box for too ling:
Sub mailSenderV2(sendTo As String, copyTo As String, subject As String, pathToFile As String)
Dim NSession As Object
Dim NUIWorkspace As Object
Dim NMailDb As Object
Dim NDocumentTemp As Object
Dim NUIDocumentTemp As Object
Dim NUIDocument As Object
Dim NRTItemBody As Object
Dim BlindCopyTo As String
Dim fileAttachment As String
fileAttachment = pathToFile ' Get the path to attachement
Set NSession = CreateObject("Notes.NotesSession") 'OLE (late binding only) because we access Notes UI classes
Set NUIWorkspace = CreateObject("Notes.NotesUIWorkspace")
Set NMailDb = NSession.GetDatabase("****", "****") ' Get BA mailbox database
Set NDocumentTemp = NMailDb.CreateDocument ' Create temp document that will be used only to put text and the zip file into
.Form = "Memo"
Set NRTItemBody = .CreateRichTextItem("Body") 'Add a rich text item to contain the email body text and file attachment
.AppendText "Hello" & Chr(10) & Chr(10) & "You will find the report below"
.EmbedObject 1454, "", fileAttachment ' Attach the zip file
.Save False, False
Set NUIDocumentTemp = NUIWorkspace.EditDocument(True, NDocumentTemp) 'Display the temporary document in the UI
With NUIDocumentTemp ' Copy out the body of the temp document
.Close 'therefore temp UI doc not saved
On Error Resume Next
NDocumentTemp.Remove True ' Delete the temp document from drafts,Causes issues if user has no rights to delete from certain mailbox
On Error GoTo 0
Application.Wait (DateAdd("s", 2, Now)) ' Wait two seconds so that it does not bug out
Set NUIDocument = NUIWorkspace.ComposeDocument(NMailDb.Server, NMailDb.FilePath, "Memo") ' Create new UI Document
.FieldSetText "EnterSendTo", sendTo ' Enter recipients
.FieldSetText "EnterCopyTo", copyTo
.FieldSetText "BlindCopyTo", BlindCopyTo
.FieldSetText "Subject", subject ' Enter subject
.Paste ' Paste from the temp document
.Document.SaveOptions = "1"
.Document.MailOptions = "1"
.Close ' close and send
The reason I use the front end is so that there is signature attached and the mail is saved in the SENT folder. But I also have this macro:
Sub mailsendervar(EmailRecipient As Variant, EmailSubject As String, pathToFile As String)
Dim Maildb As Object
Dim MailDoc As Object
Dim Body As Object
Dim Session As Object
'Start a session to notes
Set Session = CreateObject("Lotus.NotesSession")
'This line prompts for password of current ID noted in Notes.INI
'or use below to supply password of the current ID
'Open the mail database in notes
Set Maildb = Session.GetDatabase("", "archive\****")
If Not Maildb.IsOpen = True Then
'Create the mail document
Set MailDoc = Maildb.CreateDocument
Call MailDoc.ReplaceItemValue("Form", "Memo")
'Set the recipient
Call MailDoc.ReplaceItemValue("SendTo", EmailRecipient)
Call MailDoc.ReplaceItemValue("Subject", EmailSubject)
'Create and set the Body content
Set Body = MailDoc.CreateRichTextItem("Body")
'Example to create an attachment (optional)
Call Body.EmbedObject(1454, "", pathToFile, "Attachment")
'Example to save the message (optional)
MailDoc.SAVEMESSAGEONSEND = True
'Send the document
'Gets the mail to appear in the Sent items folder
Call MailDoc.ReplaceItemValue("PostedDate", Now())
Set Maildb = Nothing
Set MailDoc = Nothing
Set Body = Nothing
Set Session = Nothing
Which is much faster. Probably because it is using only back-end part.
What I like about the first code is that there is a signature attached and that the mail is saved in SENT folder
What I dont like about the second code is that there is no signature, I have to enter password and it is probably being sent from archive version of the mailbox(which I am not sure if it affects the speed).
Is there A way I could do all of this in back-end and also attach a signature and save the mail in SENT mailbox and not use the archive ?
EDIT: I ve noticed that the first code uses notes.notessession while the second uses lotus.notessession. Some methods from one dont work on the other.
And for example this line: Set Maildb = Session.GetDatabase("", "archive\****") using credentials from the first one takes long and then the line Call Maildb.Open throws out an error that database open failed.
So i believe I want to use the lotus.notessession because it is faster, but now I cant open the database.
EDIT2: I believe it was faster because the second code is using local archive file while the first one is using server.