How can we help?

How can I embed images in my e-mail?


The most common way to embed images in an HTML e-mail is by adding them as an attachment using a content-id attribute and then referencing them from an ‘IMG’ tag directly.

The Auron Email component adds content-id attributesĀ  to attachments automatically. The first attachment will have ID = 0, the next will have ID = 1, etc.

Use the following example to send an e-mail with an embedded image using the Auron E-mail component:

Set objSmtp = CreateObject("AxEmail.Smtp")
Set objMail = CreateObject("AxEmail.Message")

' component info
WScript.Echo "Auron Email Component " & objSmtp.Version
WScript.Echo "Build: " & objSmtp.Build & vbCrLf & "Module: " & objSmtp.Module

' compose e-mail
objMail.Subject       = "Testing image in footer"
objMail.BodyPlainText = "Hi, this is an official e-mail from MyCompany - Greetings!"
objMail.BodyHtml      = "<p>Hi, this is an official e-mail from MyCompany</p>" & _
  "<p>Greetings!</p><img src=""cid:0"">" ' Refer to first attachment with cid:0
objMail.AddTo           "customer@theircompany.com"
objMail.AddAttachment   "logo_rgb.png" ' First attachment contains the image

' connect to smtp server
objSmtp.HostPort = 587
objSmtp.Connect "mail.mycompany.com", "me@mycompany.com", "P@ssword"
Wscript.Echo "Connect, result: " & objSmtp.LastError & " (" & _
  objSmtp.GetErrorDescription( objSmtp.LastError ) & ")"
If (objSmtp.LastError <> 0) Then
    WScript.Quit
End If

' send e-mail
objSmtp.Send objMail 
WScript.Echo "Send, result: " & objSmtp.LastError & " (" & _
  objSmtp.GetErrorDescription( objSmtp.LastError ) & ")"
WScript.Echo "Last response from SMTP Server: " & objSmtp.LastSmtpResponse 
 
' disconnect
objSmtp.Disconnect
WScript.Echo "Disconnected."

WScript.Echo "Ready."