Hello TCoffee,
I have an Invoice program I wrote to save the worksheet as PDF and then email it using my Gmail account. You will need to edit the code to change the User Name, Password, Email address or addresses, subject line, and the email body to match your own.
This code will run correctly if you are signed into to your gmail account.
Sub SendCDOEmail()
Dim EmailAddr As String
Dim EmailBody As String
Dim FileName As String
Dim HTMLbody As String
Dim JobSite As String
Dim cdoMail As Object
Dim Password As String
Dim SendTo As String
Dim UserName As String
UserName = "" ' // Your Gmail User Name
Password = "" ' // Your Gmail Password
EmailAddr = "" ' // Your Gmail email address
SendTo = "" ' // Email recipient
Subject = "" ' // The subject of your email
FileName = "" ' // Full path of the file to be attached
JobSite = "<b>" & Replace(Range("C8"), "c/o", "") & "</b>"
Set cdoMail = CreateObject("cdo.message")
' // Default email message.
HTMLbody = "<!DOCTYPE html>"
HTMLbody = HTMLbody & "<p>Dear " & Range("C7").Text & ",<br><br>"
HTMLbody = HTMLbody & "Attached is the " & LCase(Range("E1").Text) & " for the job at " & JobSite & ". Please review the job for correctness. <br>"
HTMLbody = HTMLbody & "If there any omissions or you want to make changes to this job, please either email me or contact David Rimer by phone.<br><br>"
HTMLbody = HTMLbody & "Thank you for using Hummingbird Tree Service!<br><br>"
HTMLbody = HTMLbody & "Sincerely,<br>"
HTMLbody = HTMLbody & "Leith Ross</p>"
HTMLbody = HTMLbody & "</body></html>"
With cdoMail.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" ' // smtp.mail.yahoo.com
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = UserName ' // User Name
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Password ' // Password
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("urn:schemas:httpmail:importance") = 1
.Item("urn:schemas:httpmail:priority") = 1
.Item("urn:schemas:mailheader:X-Priority") = 1
.Update
End With
With cdoMail
.From = EmailAddr
.to = SendTo
.Subject = Subject
.HTMLbody = HTMLbody
.TextBody = EmailBody
.AddAttachment FileName
.Send
End With
End Sub
Bookmarks