Create Email but don't Send - Lotus Notes

Sean Stevens

Board Regular
Joined
Jul 24, 2003
Messages
123
I have the following code which creates an email and sends it. Works fine.

However, I was wondering if it was possible for the email to be created and not sent. This will give the user the oppertunity to enter some comments into the body of the email. I know I can do this through the use of an inputbox, but I really want them to enter the comments via their email client.

Sub EmailFile ()
' Declare Variables for file and macro setup

Dim UserName As String
Dim MailDbName As String
Dim Maildb As Object
Dim MailDoc As Object
Dim AttachME As Object
Dim Session As Object
Dim EmbedObj1 As Object

' Open and locate current LOTUS NOTES User

Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
Else
Maildb.OPENMAIL
End If

' Create New Mail and Address Title Handlers

Set MailDoc = Maildb.CreateDocument

MailDoc.Form = "Memo"
MailDoc.SendTo = "email@web.com"


MailDoc.Subject = "BEN New Project"
MailDoc.Body = _
"Attached is a new BEN Project Request. Please let me know when it has been setup."

' Select Workbook to Attach to E-Mail

MailDoc.SaveMessageOnSend = False
attachment1 = "C:\Temp\New BEN Project.xls" ' Required File Name

If attachment1 <> "" Then
On Error Resume Next
Set AttachME = MailDoc.CREATERICHTEXTITEM("attachment1")
Set EmbedObj1 = AttachME.embedobject(1454, "attachment1", "C:\Temp\New BEN Project.xls", "") 'Required File Name
On Error Resume Next
End If

MailDoc.PostedDate = Now()
On Error GoTo errorhandler1
MailDoc.Send 0, Recipient

Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing

errorhandler1:

Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing

With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With

End Sub

Thanks, Sean.
 
I used to have that kind of problem too. But just one thing, there are settings you might need to change, maybe an IP or something because it is something that will make everything work for your email though. Thanks for the update. nice one!

Hotmail
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
This code is working great with my LN8.0. Anyone can help to modify this to create mutli mail? I wish can let the code read Column A1 : Axxxx until it's blank and create mail from A1,B1,C1, as receipent, subject, cc list, message body.

NateO:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Thanks for the original code below which attaches and sends the active workbook through Lotus Notes.<o:p></o:p>
<o:p></o:p>
I removed the:<o:p></o:p>
<o:p></o:p>
MailDoc.PostedDate = Now()
On Error GoTo errorhandler1
MailDoc.Send 0, Recipient<o:p></o:p>
<o:p></o:p>
...and replaced it with:<o:p></o:p>
<o:p></o:p>
Set workspace = CreateObject("Notes.NotesUIWorkspace")
Call workspace.EDITDOCUMENT(True, MailDoc).GOTOFIELD("Body")<o:p></o:p>
(I found this in http://www.ozgrid.com/forum/showthread.php?t=18259)<o:p></o:p>
<o:p></o:p>
...which keeps the email message open instead of sending.<o:p></o:p>
<o:p></o:p>
Also, I changed the Recipient to ccRecipient, so the user can type whichever email address he needs to address to from his custom drop-down list within Lotus Notes, and type his message in the body of the email. This is the setup that is most useful for my purposes.<o:p></o:p>
<o:p></o:p>
The only thing I'm having trouble with is:<o:p></o:p>
<o:p></o:p>
1. After the user revises the workbook, but forgets to click save, if the user runs the code, it will send the workbook WITHOUT the revisions. How can I integrate coding within this same module to save the workbook before attaching it to the email?<o:p></o:p>
<o:p></o:p>
2. How can I disable the dialog box that pops up, which the user needs to click OK? It's the dialog box that contains the FilePath of the workbook. I tried setting DisplayAlerts to False, but that didn't work. I'm new to VBA. I just want the code to run and open the email message without that dialog box.<o:p></o:p>
<o:p></o:p>
3. When the code is run, the Lotus Notes email message window remains in the background behind all the other open windows. How can I get it to pop up in front of all the other windows automatically?<o:p></o:p>
<o:p></o:p>
NateO, below is your code, which I modified per my comments above:<o:p></o:p>
<o:p></o:p>
Sub LotusNotsSendActiveWorkbook()
'Send an e-mail & attachment using Lotus Not(s)
'Original Code by Nate Oliver (NateO)<o:p></o:p>
'Declare Variables for file and macro setup<o:p></o:p>
Dim UserName As String, MailDbName As String, ccRecipient As String, attachment1 As String
Dim Maildb As Object, MailDoc As Object, AttachME As Object, Session As Object
Dim EmbedObj1 As Object<o:p></o:p>
With Application
.ScreenUpdating = False
.DisplayAlerts = False<o:p></o:p>
<o:p></o:p>
' Open and locate current LOTUS NOTES User
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = _
Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
Else
Maildb.OPENMAIL
End If<o:p></o:p>
<o:p></o:p>
' Create New Mail and Address Title Handlers
Set MailDoc = Maildb.CreateDocument<o:p></o:p>
MailDoc.Form = "Memo"<o:p></o:p>
' Select range of e-mail addresses
ccRecipient = Sheets("EmailSheet").Range("B2").Value
' Or send to a signle address
' Recipient = "yourname@isp.com"
MailDoc.CopyTo = ccRecipient<o:p></o:p>
' Subject & Body stored in a**worksheet
MailDoc.Subject = Sheets("EmailSheet").Range("C2").Value
' MailDoc.Body = Sheets("EmailSheet").Range("ENTER CELL OF BODY").Value
' These can be entered here manually instead
' MailDoc.Subject = "Check this out!"
' MailDoc.Body = "Made you look!"<o:p></o:p>
<o:p></o:p>
' Select Workbook to Attach to E-Mail
MailDoc.SaveMessageOnSend = True
MsgBox ActiveWorkbook.FullName
attachment1 = ActiveWorkbook.FullName<o:p></o:p>
If attachment1 <> "" Then
On Error Resume Next
Set AttachME = MailDoc.CREATERICHTEXTITEM("attachment1")
Set EmbedObj1 = AttachME.EmbedObject(1454, "attachment1", ActiveWorkbook.FullName, "")
On Error Resume Next
End If<o:p></o:p>
<o:p></o:p>
'Displays email message without sending; user needs to click Send
Set workspace = CreateObject("Notes.NotesUIWorkspace")
Call workspace.EDITDOCUMENT(True, MailDoc).GOTOFIELD("Body")<o:p></o:p>
<o:p></o:p>
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing<o:p></o:p>
<o:p></o:p>
.ScreenUpdating = True
.DisplayAlerts = True
End With<o:p></o:p>
<o:p></o:p>
errorhandler1:<o:p></o:p>
<o:p></o:p>
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing<o:p></o:p>
<o:p></o:p>
End Sub
 
Upvote 0
I am very new to creating macros, but have found these posts extremely helpful. My one problem is with switching the ccRecipient back to the regular Recipient. How can I do this? I still want to use a reference cell that is then looked up in my lotus notes directory, but I want this done in the regular recipient's box not the cc.
 
Upvote 0
This is awesome, I've been looking for this for so long and it works great. Just wondering though, the email is generated from the user:

' Open and locate current LOTUS NOTES User
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = _
Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
Else
Maildb.OPENMAIL
End If

Can it be created from a specific mail box the user has access to, e.g. team inbox or teaminbox@company.com?

Cheers,
 
Upvote 0
I have been messing around with this - very new to this stuff as well, but I think this is what you are looking for:

MailDoc.SendTo = Recipient ' Email addresses in Send to Field
MailDoc.CopyTo = ccRecipient ' Email addresses in Copy to Field
 
Upvote 0
Thanks for the code. This is working great except that the MailDoc.Body is placed under the signature that I have in Lotus Notes 8.5. How do I move it up in the actual body of the email?:confused:
 
Upvote 0
Does anyone have this bug the MailDoc.SendTo = have n email but Lotus only send to the first email all other are cut.
 
Upvote 0
can anyone help with revising this code to only send the active worksheet rather then the whole workbook?
 
Upvote 0

Forum statistics

Threads
1,223,712
Messages
6,174,031
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top