ImportMailEx Method


Imports specified html file or URL with embedded pictures/images to current email.

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

Parameters

FileName
A vaild file or URL with full path.

Return Value

Return zero if successful, return non-zero if failed.

Remarks

This method loads a local or remote html file to email body text, and automatically adds all pictures involved as embedded attachments to this email. All pictures must be in your local disk, otherwise this method couldn't add all pictures correctly.
This method automatically sets email body format to 1 (HTML).

Example

[Visual Basic, Delphi, Visual C++] The following example demonstrates how to import remote & local html source with EASendMail SMTP Component. To get the full samples of EASendMail, please refer to Samples section.


[VB6, VBA - Import Html Body and Embedded Image]
Private Sub btnSendMail_Click()

  Dim oSmtp As New EASendMailObjLib.Mail
  oSmtp.LicenseCode = "TryIt"
 
  ' test.htm contains the following content:
  '<html><body>this is an inline <img src="c:\my pictures\test.gif"> image</body></html>  
       
  ' test.gif will be imported as embedded image in the email
  oSmtp.ImportMailEx "c:\my folder\test.htm"

  ' You save it to EML file or call SendMail method to send this email out
  oSmtp.SaveMail "c:\test.eml"        

End Sub

[Delphi - Import Html Body and Embedded Image]
Procedure TForm1.Button1Click(Sender: TObject);
var:
  oSmtp: TMail;
begin
  oSmtp := TMail.Create(Application);
  oSmtp.LicenseCode = 'TryIt'
  
  // test.htm contains the following content:
  // <html><body>this is an inline <img src="c:\my pictures\test.gif"> image</body></html>  
       
  // test.gif will be imported as embedded image in the email
  oSmtp.ImportMailEx( 'c:\my folder\test.htm' );

  // You save it to EML file or call SendMail method to send this email out
  oSmtp.SaveMail( 'c:\test.eml' );

 end;

[Visual C++ - Import Html Body and Embedded Image]
#include "stdafx.h" 

#include "easendmailobj.tlh" 
using namespace EASendMailObjLib; 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    ::CoInitialize( NULL ); 

    IMailPtr oSmtp = NULL; 
    oSmtp.CreateInstance( __uuidof(EASendMailObjLib::Mail)); 
    oSmtp->LicenseCode = _T("TryIt"); 

    // test.htm contains the following content:
    // <html><body>this is an inline <img src="c:\my pictures\test.gif"> image</body></html>  

    // test.gif will be imported as embedded image in the email     
    oSmtp->ImportMailEx(_T("c:\\my folder\\test.htm"));

    // You save it to EML file or call SendMail method to send this email out
    oSmtp.SaveMail( _T("c:\\test.eml"));

    if( oSmtp != NULL ) 
        oSmtp.Release(); 

    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

AddInline Method
ImportHtml Method