Hello all! Trying to generate an automated email with Gmail that includes a screenshot of a previously generated image but it's only showing the alternate text as defined in .HTMLbody. I've confirmed the HTML code works in a localized file but it's not showing in the email. Any help would be greatly appreciated!
Code:
Enter your GMail credentials here and whoever you would like to send this report to.
email = ""
pass = ""
msgTO = email
msgCC = ""
msgBCC = ""
' Had to remove the <> to avoid the actual document being counted as a live HTML tag.
body = "img src='C:\Users\john.doe\Exports\agentDev.png' alt='Agent Development Chart'"
Set NewMail = CreateObject("CDO.Message")
Set mailConfig = CreateObject("CDO.Configuration")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ActiveWorkbook.Sheets.Copy
ActiveWorkbook.Worksheets(1).Shapes("send").Delete
ActiveWorkbook.Worksheets(1).Shapes("update").Delete
ActiveWorkbook.Worksheets(1).Shapes("close").Delete
ActiveWorkbook.SaveAs Filename:="agent.xlsx", FileFormat:=51
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
mailConfig.Load -1
Set fields = mailConfig.fields
With NewMail
.Subject = ""
.From = email
.To = msgTO
.CC = msgCC
.BCC = msgBCC
.htmlbody = body
.AddAttachment "agent.xlsx"
End With
msConfigURL = "http://schemas.microsoft.com/cdo/configuration"
With fields
.Item(msConfigURL & "/smtpusessl") = True
.Item(msConfigURL & "/smtpauthenticate") = 1
.Item(msConfigURL & "/smtpserver") = "smtp.gmail.com"
.Item(msConfigURL & "/smtpserverport") = 465
.Item(msConfigURL & "/sendusing") = 2
.Item(msConfigURL & "/sendusername") = email
.Item(msConfigURL & "/sendpassword") = pass
.update
End With
NewMail.Configuration = mailConfig
NewMail.Send
Kill "agent.xlsx"
Last edited: