VBA. How to .display CDO.message and attach the active Excel Workbook?

elnino

New Member
Joined
Feb 10, 2018
Messages
2
[FONT=&quot]I have a code using CDO.message in VBA to send email from excel through Gmail.[/FONT]
[FONT=&quot]I can successfully send emails and also attach different files. BUT![/FONT]
[FONT=&quot]1. I want to be able see/edit email before sending it! If i am not mistaken ".display" does not work for CDO.message. Any other way to get around that?[/FONT]
[FONT=&quot]2. I can attach saved files. But I want to attach current open file from which I am using macro. I do not necessarily need to save the file after i email it.[/FONT]
[FONT=&quot]Here is my code:[/FONT]
[FONT=&quot]Sub sendemail()

Dim mymail As CDO.message
Set mymail = New CDO.message

mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "*********@gmail.com"
mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "*******"
mymail.Configuration.Fields.Update

With mymail
.Subject = "Test Email from El"
.From = "******@gmail.com"
.To = ""
.CC = ""
.BCC = ""
.TextBody = "Goor morning!"
.AddAttachment "c:\..."
.Send
End With

On Error Resume Next

If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "there was an error"
Exit Sub
End If
MsgBox ("mail has been sent")
Set mymail = Nothing

End Sub
[/FONT]
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,215,324
Messages
6,124,250
Members
449,149
Latest member
mwdbActuary

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