ImportHtml Method


Imports HTML source from string to HTML body of the e-mail message. This method also import linked images/pictures in the HTML source to embedded images.

[Syntax]
Visual C++: HRESULT ImportHtml(BSTR  Html, BSTR BasePath, long* pVal)
Visual Basic: ImportHtml(Html As String, BasePath As String) As Long

Parameters

Html
Html source code to import
BasePath
Root path for embedded pictures that uses relative path in html source. Because ImportHtml method automatically imports linked pictures into current email as embedded pictures, if the link uses relative path, then BasePath helps Mail object to change relative path to absolute path. e.g. picture locates at "http://emailarchitect.net/test.gif", and in html source it presents <img src="test.gif">, then the BasePath should be "http://emailarchitect.net/"

Return Value

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

Remarks

This method loads html string to email body text, and automatically adds all pictures/images involved as embedded attachments to this email. This method is very simliar with ImportMailEx method.
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.gif is in c:\my picture     
  ' test.gif will be imported as embedded image in the email
  oSmtp.ImportHtml "<html><body>test <img src=""test.gif""> importhtml</body></html>", _
	"c:\my picture"

  ' 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.gif is in c:\my picture // test.gif will be imported as embedded image in the email oSmtp.ImportHtml('<html><body>test <img src="test.gif"> importhtml</body></html>', 'c:\my picture'); // 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.gif is in c:\my picture // test.gif will be imported as embedded image in the email oSmtp->ImportHtml(_T("<html><body>test <img src=\"test.gif\"> importhtml</body></html>"), _T("c:\my picture")); // You save it to EML file or call SendMail method to send this email out oSmtp.SaveMail(_T("c:\\test.eml")); 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
ImportMailEx Method