I have a button on a form to send an email to an address in a textbox. The code works fine and sends the email correctly except for the embedded image. That does not show up. I tried the .AddAttachment with the cid: but that just displays the attachment and not the embedded image.
Dim NewMail As Object
Dim mailConfig As Object
Dim fields As Variant
Dim msConfigURL, TextBody1, TextBody2, StrBody As String
On Error GoTo Err:
'late binding
Set NewMail = CreateObject("CDO.Message")
Set mailConfig = CreateObject("CDO.Configuration")
' load all default configurations
mailConfig.Load -1
Set fields = mailConfig.fields
StrBody = "Hello " & TextBox2.Value & ", <p> " & _
"Please verify your squad selection and average division,<br>" & _
"And please reply with correct information if an error is found.<p>" & _
"Squad: " & ComboBox1.Value & ", <br> " & _
"Average: " & TextBox9.Value
'Set All Email Properties
With NewMail
enable_html = True
.From = "[email protected]" 'normally my email account
.To = TextBox7.Value
.CC = ""
.BCC = ""
.Subject = "40 Frame Game Tournament Confirmation " & Format(Date, "m/d/yy")
.AddAttachment "C:\Users\bradb\OneDrive\Desktop\SWC-Signature.png", 1, 0
.HTMLBody = "<HTML><BODY style=font-size:18pt; font-family:Arial;>" & StrBody & _
"<img src='cid:SWC-Signature.png'" & "width='375'>" & _
"<p>Thank You<br>Brad Bylls<br>Tournament Manager</p></BODY></HTML>"
End With
msConfigURL = "http://schemas.microsoft.com/cdo/configuration"
With fields
.Item(msConfigURL & "/smtpusessl") = True 'Enable SSL Authentication
.Item(msConfigURL & "/smtpauthenticate") = 1 'SMTP authentication Enabled
.Item(msConfigURL & "/smtpserver") = "smtp.gmail.com" 'Set the SMTP server details
.Item(msConfigURL & "/smtpserverport") = 465 'Set the SMTP port Details
.Item(msConfigURL & "/sendusing") = 2 'Send using default setting
.Item(msConfigURL & "/sendusername") = "[email protected]" 'Your gmail address
.Item(msConfigURL & "/sendpassword") = "**** **** **** ****"
.Update 'Update the configuration fields
End With
NewMail.Configuration = mailConfig
NewMail.Send
"<img src='data:image/jpeg;base64," & imageData & "' width='300'>"whereimageDatais a string representing the encoded image file. For encoding see (eg) stackoverflow.com/a/41638989/478884<img>tag.