Embedding images and files

Visual Basic Code | ASP Code

The sample sends HTML message with embedded image.

Although it is possible to embed files (usually images) indirectly (by importing HTML file which references them, see HTML e-mail from a file sample), you can still embed them manually.

Embedded objects are attachments referenced in the message body: images, sounds, scripts, style-sheets and all other files required to properly display the message body.

In the message body, embedded objects are related through Content-IDs (CIDs). Thus, Content-ID in the body must match Content-ID of attachment that holds the embedded object.

In the sample code, embedded image is added as attachment with Content-ID set to "pic1". The message body contains <IMG> tag with SRC="cid:pic1". This will cause HTML-capable mail clients to display embedded image in this <IMG> tag.

For simplicity, SMTP authentication is not used and no error-checking is performed.


[Visual Basic]:

Dim objSMTP

' Create mailer component
Set objSMTP = CreateObject("MailBee.SMTP")

' Unlock SMTP component
objSMTP.LicenseKey = "put your license key here"

' Set SMTP server name
objSMTP.ServerName = "mail.server.com"

' Set message properties
objSMTP.FromAddr = "me@mydomain.com"
objSMTP.ToAddr = "you@yourdomain.com"
objSMTP.Subject = "HTML message with embedded image"

' Set HTML format for the body
objSMTP.BodyFormat = 1

' Place HTML contents (IMG tag) into the body
objSMTP.BodyText = "<html><img src='cid:pic1'></html>"

' Embed image (add as attachment with Content-ID value set)
objSMTP.AddAttachment "C:\images\signature.jpg", ,"pic1"

' Send it!
objSMTP.Send

[ASP]:

<%
Dim objSMTP

' Create mailer component
Set objSMTP = Server.CreateObject("MailBee.SMTP")

' Unlock SMTP component
objSMTP.LicenseKey = "put your license key here"

' Set SMTP server name
objSMTP.ServerName = "mail.server.com"

' Set message properties
objSMTP.FromAddr = "me@mydomain.com"
objSMTP.ToAddr = "you@yourdomain.com"
objSMTP.Subject = "HTML message with embedded image"

' Set HTML format for the body
objSMTP.BodyFormat = 1

' Place HTML contents (IMG tag) into the body
objSMTP.BodyText = "<html><img src='cid:pic1'></html>"

' Embed image (add as attachment with Content-ID value set)
objSMTP.AddAttachment "C:\images\signature.jpg", ,"pic1"

' Send it!
objSMTP.Send
%>
See Also:
AddAttachment Method

 


Send feedback to AfterLogic
Copyright © 2002-2022, AfterLogic Corporation. All rights reserved.