Fire_Chief
Well-known Member
- Joined
- Jun 21, 2003
- Messages
- 690
- Office Version
- 365
- Platform
- Windows
I need the code to send CDO mail to a gmail account. I have tried many times to get
This is driving me crazy.
Ron de Bruins code to work but just can't get it.
VBA Code:
Sub SEND_PDF_SHEET_WITH_CDO()
Dim filepath As String
filepath = Environ$("temp") & "\" & ActiveWorkbook.Name & ".pdf" 'TODO:change filepath for the temp pdf file
Range("A5:P39").Select ' In excel worksheet
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
filepath, _
Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
'Setting up CDOSYS configuration to send out the email
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
.Item("http://schemas.Microsoft.Com/cdo/configuration/smtpusetls") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = True
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "someone@somewhere.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = my password
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtp.gmail.com
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
.Update
End With
With iMsg
Set .Configuration = iConf
.From = "someone@somewhere.com"
.To = Range("JA3").Value
.Subject = Range("A346").Value
.HTMLBody = Range("A350").Value
.AddAttachment (filepath)
.Send ' THIS IS WHERE I GET AN ERROR = Run_time error '-2147220973 (80040213)':
End With
Set iMsg = Nothing
Set iConf = Nothing
Kill filepath
Set iMsg = Nothing
Set iConf = Nothing
Kill filepath
End Sub
This is driving me crazy.
Last edited by a moderator: