AddInline Method


Add an embedded image file to current email.

[Syntax]
Visual C++: HRESULT AddInline(BSTR FileName, BSTR* pVal)
Visual Basic: AddInline(FileName As String) As String 

Parameters

FileName
File or URL to be added.

Return Value

If this method succeeds, the return value is the Content-ID generated automatically by this method; otherwise the return value is null.

Remarks

In some cases, the e-mail body includes a hyper-link which refers to a picture. In order to embed the picture in current email, you can use AddInline/AddInlineEx method. First developer can use AddInline/AddInlineEx method to add a picture to an e-mail, then change the hyper-link so that it points to <img src="cid:Content-ID">. This Content-ID is returned by this method.
To attach embedded images or inline images, Mail.ImportHtml and Mail.ImportMailEx methods are strongly recommended.

Example

[Visual Basic, Visual C++, Delphi] To get the full samples of EASendMail, please refer to Samples section.

[VB6, VBA - Send Email with Embedded Images]

Const ConnectNormal = 0
Const ConnectSSLAuto = 1
Const ConnectSTARTTLS = 2
Const ConnectDirectSSL = 3
Const ConnectTryTLS = 4

Private Sub btnSendMail_Click() 

    Dim oSmtp As New EASendMailObjLib.Mail 
    oSmtp.LicenseCode = "TryIt" 

    ' Your SMTP server address
    oSmtp.ServerAddr = "smtp.emailarchitect.net"

    ' User and password for ESMTP authentication
    oSmtp.UserName = "test@emailarchitect.net"
    oSmtp.Password = "testpassword"

    ' ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically
    oSmtp.ConnectType = ConnectTryTLS

    ' Set your sender email address
    oSmtp.FromAddr = "test@emailarchitect.net" 

    ' Add recipient email address
    oSmtp.AddRecipientEx "support@emailarchitect.net", 0 

    ' Set email subject
    oSmtp.Subject = "test HTML email from VB 6.0 with embedded images" 

    Dim cid As String 
    ' Add embedded image and return the unique identifier of the attachment
    cid = oSmtp.AddInline("c:\test.gif") 
    If cid = "" Then 
        MsgBox "failed add embedded image with error:" & oSmtp.GetLastErrDescription() 
        Exit Sub 
    End If 

    ' Set HTML body format
    oSmtp.BodyFormat = 1 

    ' Use the cid as link in the body text
    oSmtp.BodyText = "<html><body>Hello, this is a embedded <img src=""cid:" & cid & _ 
            """ > picture.</body><html>" 

    MsgBox "start to send email ..." 

    If oSmtp.SendMail() = 0 Then 
        MsgBox "email was sent successfully!" 
    Else 
        MsgBox "failed to send email with the following error:" & oSmtp.GetLastErrDescription() 
    End If 

End Sub 


[Delphi - Send Email with Embedded Images] Unit Unit1; Interface Uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, EASendMailObjLib_TLB; // add EASendMail Unit Type TForm1 = Class(TForm) Button1: TButton; Procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } End; const ConnectNormal = 0; ConnectSSLAuto = 1; ConnectSTARTTLS = 2; ConnectDirectSSL = 3; ConnectTryTLS = 4; Var Form1: TForm1; Implementation {$R *.dfm} Procedure TForm1.Button1Click(Sender: TObject); Var oSmtp : TMail; cid : WideString; Begin oSmtp := TMail.Create(Application); oSmtp.LicenseCode := 'TryIt'; // Your SMTP server address oSmtp.ServerAddr := 'smtp.emailarchitect.net'; // User and password for ESMTP authentication, oSmtp.UserName := 'test@emailarchitect.net'; oSmtp.Password := 'testpassword'; // ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically oSmtp.ConnectType := ConnectTryTLS; // Set your sender email address oSmtp.FromAddr := 'test@emailarchitect.net'; // Add recipient email address oSmtp.AddRecipientEx('support@emailarchitect.net', 0); // Set email subject oSmtp.Subject := 'test HTML email from Delphi with embedded images'; // Add embedded image and return the unique identifier of the attachment cid := oSmtp.AddInline('c:\test.jpg'); If cid = '' Then Begin ShowMessage('Failed to add embedded image with error: ' + oSmtp.GetLastErrDescription()); exit; End; // Set HTML body format oSmtp.BodyFormat := 1; // Set HTML body oSmtp.BodyText := '<html><body>Hello, this is an embedded <img src="cid:' + cid + '"> picture.</body></html>'; ShowMessage('start to send email ...'); If oSmtp.SendMail() = 0 Then ShowMessage('email was sent successfully!') Else ShowMessage('failed to send email with the following error: ' + oSmtp.GetLastErrDescription()); End; End.
[Visual C++ - Send Email with Embedded Images] #include "stdafx.h" #include <tchar.h> #include <Windows.h> #include "EASendMailObj.tlh" using namespace EASendMailObjLib; const int ConnectNormal = 0; const int ConnectSSLAuto = 1; const int ConnectSTARTTLS = 2; const int ConnectDirectSSL = 3; const int ConnectTryTLS = 4; int _tmain(int argc, _TCHAR* argv[]) { ::CoInitialize(NULL); IMailPtr oSmtp = NULL; oSmtp.CreateInstance(__uuidof(EASendMailObjLib::Mail)); oSmtp->LicenseCode = _T("TryIt"); // Your SMTP server address oSmtp->ServerAddr = _T("smtp.emailarchitect.net"); // User and password for ESMTP authentication oSmtp->UserName = _T("test@emailarchitect.net"); oSmtp->Password = _T("test"); // ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically oSmtp->ConnectType = ConnectTryTLS; // Set your sender email address oSmtp->FromAddr = _T("test@emailarchitect.net"); // Add recipient email address oSmtp->AddRecipientEx(_T("support@emailarchitect.net"), 0); // Set email subject oSmtp->Subject = _T("HTML email from Visual C++ project with inline image"); // Add embedded image and return the unique identifier of the attachment _bstr_t cid = oSmtp->AddInline(_T("c:\\test.gif")); if(cid.length() == 0) { _tprintf(_T("failed add embedded image with error: %s"), (const TCHAR*)oSmtp->GetLastErrDescription()); } // Set HTML body format oSmtp->BodyFormat = 1; // Use the cid as link in the body text oSmtp->BodyText = _bstr_t("<html><body>Hello, this is a embedded <img src=\"cid:") + cid + _bstr_t("\" > picture.</body><html>"); _tprintf(_T("Start to send HTML email with embedded image ...\r\n")); if(oSmtp->SendMail() == 0) { _tprintf(_T("email was sent successfully!\r\n")); } else { _tprintf(_T("failed to send email with the following error: %s\r\n"), (const TCHAR*)oSmtp->GetLastErrDescription()); } return 0; }

Online Examples

Visual C++ - Send HTML Email with Embedded Images
Visual Basic - Send HTML Email with Embedded Images
Delphi - Send HTML Email with Embedded Images

See Also

ImportHtml
ImportMailEx
ClearInline Method
AddAttachment Method