1

I need to send automated e-mails with the logo of my company on signature.

I'm using the HTMLBody property of the mail object, but it doesn't show the image. Instead it shows a symbol and the alt property of img HTML tag.

Is there a special directory where I must place the image files to use them in mail's body?

Sub AutoMail()

   'creating a CDO object
   Dim Mail As CDO.Message
   Set Mail = New CDO.Message

   'Enable SSL Authentication
   Mail.Configuration.Fields.Item _
   ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

   'Make SMTP authentication Enabled=true (1)
   Mail.Configuration.Fields.Item _
   ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

   'Set the SMTP server and port Details
   'Get these details from the Settings Page of your Gmail Account
   Mail.Configuration.Fields.Item _
   ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
   "smtp.gmail.com"
   Mail.Configuration.Fields.Item _
   ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
   Mail.Configuration.Fields.Item _
   ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

   'Set your credentials of your Gmail Account
   Mail.Configuration.Fields.Item _
   ("http://schemas.microsoft.com/cdo/configuration/sendusername") = _
   "****@****.com"
   Mail.Configuration.Fields.Item _
   ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = _
   "*****"

   'Update the configuration fields
   Mail.Configuration.Fields.Update
    
    'Set All Email Properties
    With Mail
        .Subject = "Test"
        .From = "***@****.com"
        .TextBody = "Hi"
        .HTMLBody = "(message) <br> <br> <img alt='hi' src='C:\logo.png'>"
   End With
   
   'To send the mail
   Mail.Send
   
   Set Mail = Nothing
      
End Sub
Community
  • 1
  • 1

1 Answers1

1

You can upload your images to any web server and add an URL to the uploaded image. But this way doesn't guarantee that images will be displayed in Outlook on the recipient's side because Outlook prevents such images from loading by default.

The most reliable way is to attach images to the mail item and then add the CID attribute to them. In the message body you can refer to such images by using the CID attribute set on the attachments. Read more about that in the Embed Images in New Messages using a Macro article.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45