Skip to main content
 
developerWorks
AIX and UNIX
Information Mgmt
Lotus
New to Lotus
Products
How to buy
Downloads
Live demos
Technical library
Training
Support
Forums & community
Events
Rational
Tivoli
WebSphere
Java™ technology
Linux
Open source
SOA and Web services
Web development
XML
My developerWorks
About dW
Submit content
Feedback



developerWorks  >  Lotus  >  Forums & community  >  Notes/Domino 6 and 7 Forum

Notes/Domino 6 and 7 Forum

developerWorks

  

Sign in to participate PreviousPrevious NextNext


Marcel Muller 24.Oct.16 05:33 AM a Web browser
Notes Client All Releases All Platforms


Hello,

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
With NDocumentTemp
.Form = "Memo"
Set NRTItemBody = .CreateRichTextItem("Body") 'Add a rich text item to contain the email body text and file attachment
With NRTItemBody
.AppendText "Hello" & Chr(10) & Chr(10) & "You will find the report below"
.AddNewLine 1
.AddNewLine 1
.EmbedObject 1454, "", fileAttachment ' Attach the zip file
.AddNewLine 1
End With
.Save False, False
End With
Set NUIDocumentTemp = NUIWorkspace.EditDocument(True, NDocumentTemp) 'Display the temporary document in the UI

With NUIDocumentTemp ' Copy out the body of the temp document
.gotofield "Body"
.SelectAll
.Copy
.Close 'therefore temp UI doc not saved
End With
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
With NUIDocument
.FieldSetText "EnterSendTo", sendTo ' Enter recipients
.FieldSetText "EnterCopyTo", copyTo
.FieldSetText "BlindCopyTo", BlindCopyTo
.FieldSetText "Subject", subject ' Enter subject
.gotofield "Body"
.Paste ' Paste from the temp document
.Document.SaveOptions = "1"
.Document.MailOptions = "1"
.Close ' close and send
End With

End Sub

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
'Call Session.Initialize
'or use below to supply password of the current ID
Call Session.Initialize("****")
'Open the mail database in notes
Set Maildb = Session.GetDatabase("", "archive\****")
If Not Maildb.IsOpen = True Then
Call Maildb.Open
End If
'Create the mail document
Set MailDoc = Maildb.CreateDocument
Call MailDoc.ReplaceItemValue("Form", "Memo")
'Set the recipient
Call MailDoc.ReplaceItemValue("SendTo", EmailRecipient)
'Set subject
Call MailDoc.ReplaceItemValue("Subject", EmailSubject)
'Create and set the Body content
Set Body = MailDoc.CreateRichTextItem("Body")
Call Body.AppendText("")
'Example to create an attachment (optional)
Call Body.AddNewLine(2)
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())
Call MailDoc.SEND(False)
'Clean Up
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 ?

Thank you

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.








  Document options
Print this pagePrint this page

 Search this forum

  Forum views and search
Date (threaded)
Date (flat)
With excerpt
Author
Category
Platform
Release
Advanced search

 Sign In or Register
Sign in
Forgot your password?
Forgot your user name?
Create new registration

 RSS feedsRSS
All forum posts RSS
All main topics RSS
More Lotus RSS feeds

Resources

 Resources
Forum use and etiquette
Native Notes Access
Web site Feedback

Lotus Support

 Lotus Support
IBM Support Portal - Lotus software
Lotus Support documents
Lotus support by product
Lotus support downloads
Lotus support RSS feeds

Wikis

 Wikis
IBM Composite Applications
IBM Mashup Center
IBM Connections
IBM Connections Cloud Developers
IBM Docs
IBM Forms
IBM Mobile Connect
IBM Sametime
IBM SmartCloud for Social Business
IBM Web Experience Factory
Lotus Domino
Lotus Domino Designer
Lotus Expeditor
Lotus Foundations
Lotus iNotes
Lotus Instructor Community Courseware
Lotus Notes
Lotus Notes & Domino Application Development
Lotus Notes Traveler
Lotus Protector
Lotus Quickr
Lotus Symphony
IBM Web Content Manager
WebSphere Portal

Lotus Forums


 Lotus Forums
Notes/Domino 9.0
Notes/Domino 8.5 + Traveler
Notes/Domino XPages development forum
Notes/Domino 8
Notes/Domino 6 and 7
IBM Connections
IBM Mobile Connect
IBM Sametime
IBM SmartCloud Notes
Lotus Enterprise Integration
Lotus Protector
Lotus Quickr
Lotus SmartSuite