Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lotus Notes e-mail question

Status
Not open for further replies.

Zygor

Technical User
Apr 18, 2001
271
0
0
US
I am using the following code and have several times. Works great! However...I need to pause the routine without sending the note. Just leave the window open so the user can select the recipient. Any help would be appreciated.

Public Sub SendNotesMail(Subject As String, attachment As String, Optional recipient As String, Optional bodytext As String, Optional saveit As Boolean)
'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)
'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.UserName
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.Subject = Subject
MailDoc.Body = bodytext
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
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
 
What happens if you comment out this line ?
MailDoc.SEND 0, recipient

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Nothing happens (or so it seems) at all.
 
it appears that you are only accessing the backend of the notes database and sending the message. In order to actually see the message you will need to access the UI document properties. I'll look and see if I can find an example and post for you.

leslie
 
That would be great. Thanks!
 
Ok, I found something!!

Code:
Dim ProPath As String
Dim response As String

Dim session As Object
Dim MailDb As Object
Dim MailDoc As Object
Dim oAttachME As Object
Dim oEmbedObj As Object
[b]
Dim uiWS As Object 'UI Workspace - Notes environment
Dim uiDoc As Object 'UI Document - Form that allows you to "see" the document you created, in this case the mail form
[/b]
Dim strAttachmentName As String

ProPath = Forms!frmConfig!DBDataPath & "\Attachments\" & Forms!frmMain!IssueID & "\"

'Purpose: Start a session to notes. This process uses OLE instead of COM since
' "Notes.NotesSession" is used instead of "Lotus.NotesSession"
Set session = CreateObject("Notes.NotesSession")

'Purpose: Opens the mail database
Set MailDb = session.GetDatabase(ServerName, MailFile)

If MailDb.IsOpen = True Then
'Already open for mail
Else
Call MailDb.Open
End If

'Purpose: Set up the new mail document
Set MailDoc = MailDb.CreateDocument

If lstIssueAttachments.Column(2) = True Then
strAttachmentName = lstIssueAttachments.Column(1)
Else
strAttachmentName = ProPath & lstIssueAttachments.Column(1)
End If

'Purpose: Creates the e-mail body and inserts the attachment
Set oAttachME = MailDoc.CreateRichTextItem("Body")
Set oEmbedObj = oAttachME.EmbedObject(1454, "", strAttachmentName)

'Purpose: Sets a special field value to tell Lotus Notes which form to use when opening
' the document. This has a specialized process that I am unsure about.
Call MailDoc.ReplaceItemValue("Form", "Memo")
[b]
'Purpose: At this point you have a document that exists only in memory. In order to
' allow text to be added to the message in Lotus Notes, you need the Notes UI
' so that you can display the document to the user. This is allowing them to
' edit the message while it is in memmory.
Set uiWS = CreateObject("Notes.NotesUIWorkspace")

Call uiWS.EDITDOCUMENT(True, MailDoc)

'Purpose: Brings Lotus Notes to the foreground
AppActivate "Lotus Notes"
[/b]
Set session = Nothing
Set MailDb = Nothing
Set MailDoc = Nothing
Set oAttachME = Nothing
Set oEmbedObj = Nothing
Set uiWS = Nothing
Set uiDoc = Nothing

now most of this you already have; what you need to look into is the bolded section. This is where you access the document you just created and display it through the UI.

Hope that helps!

For future reference, I found this code at in the Forums. I searched for 'VBA open new mail' and got 11 hits. As far as I can tell this should do what you want, but if not go check out the notes forum!

Good luck!

Leslie
 
Zygor,

I have attempted to use your code in the first note and when I try to use the procedure in a routine, with the following code

SendNotesMail("Test","C:\Test\Test.doc" ,"martin.lymn@ars.aon.co.uk","This is test of the automatic email procedure",false)

When I type this code in I am getting a compile error saying
Expected : =

Can you give me any pointers as to what I am doing wrong.

Thanks in Advance

Ozzie
 
Try;

If SendNotesMail is a Sub or
if it is a Function and you are not interested in a return value use;

SendNotesMail "Test","C:\Test\Test.doc" ,"martin.lymn@ars.aon.co.uk","This is test of the automatic email procedure",false

If SendNotesMail is a Function and you are interested in a return value use;

MyVariable = SendNotesMail ("Test","C:\Test\Test.doc" ,"martin.lymn@ars.aon.co.uk","This is test of the automatic email procedure",false)

The following is in vb6 but
Lotus Notes Body Text/ Email VB - thread222-766157 may also be of interest.

Hugh,

 
Cheers Hugh.

Works great now.

Any idea how to send from a group email account rather than my personal one in Lotus Notes.

Thanks

Ozzie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top