AltBody Property


This property specifies alternative body of current email.

Data Type: String

Remarks

In some cases, an email consists of two bodies. One is in text/html format, and another one is in text/plain format. It is called multipart/alternative format. AltBody property specifies text/plain part of an email. Why alternative? Suppose that the recipient's email client doesn't support html email, if AltBody is specified, email client will shows the AltBody.

BodyFormat property must be set to 1 (text/html) to take effect.

Examples

[VB, VC++] To get the full samples of EASendMail, please refer to Samples section.

[VB6, VBA - Send Email with Alternative Body]
Private Sub SendEmail()
  Dim oSmtp As EASendMailObjLib.Mail
  Set oSmtp = New EASendMailObjLib.Mail
  
  'The license code for EASendMail ActiveX Object, 
  'for evaluation usage, please use "TryIt" as the license code.
  oSmtp.LicenseCode = "TryIt"
  
  oSmtp.ServerAddr = "mail.adminsystem.net"
  
  'If your server require user authentication 
  'oSmtp.UserName = "test@adminsystem.net"
  'oSmtp.Password = "test"
  
  'If your server requires SSL connection 
  'oSmtp.SSL_init 
  'oSmtp.SSL_starttls = 0 
  'oSmtp.ServerPort = 465
  
  ''If your server requires TLS connection 
  'oSmtp.SSL_init 
  'oSmtp.SSL_starttls = 1 
  'oSmtp.ServerPort = 25
   
  oSmtp.FromAddr = "test@adminsystem.net"
  oSmtp.AddRecipient "Support Team", "support@adminsystem.net", 0

  oSmtp.BodyFormat = 1
  oSmtp.Subject = "Test"
  oSmtp.BodyText = "<html>..<body>Hello, this is a test...."
  oSmtp.AltBody = "Hello, this is a test"
 
  If oSmtp.SendMail() = 0 Then
    MsgBox "Message delivered!"
  Else
    MsgBox oSmtp.GetLastErrDescription()
  End If
End Sub

[Visual C++ - Send Email with Alternative Body]
#include "stdafx.h"
#include <comdef.h>
#include <iostream>

#include "easendmailobj.tlh"
using namespace EASendMailObjLib;
using namespace std;

void SendEmail()
{
  ::CoInitialize( NULL );
  IMailPtr oSmtp = NULL;
  oSmtp.CreateInstance(__uuidof(EASendMailObjLib::Mail));
  //The license code for EASendMail ActiveX Object, 
  //for evaluation usage, please use "TryIt" as the license code.
  oSmtp->LicenseCode = _T("TryIt");
	
	
  oSmtp->ServerAddr = _T( "mail.adminsystem.net" );
  //If your server require user authentication 
  //oSmtp->UserName = _T("test@adminsystem.net"); 
  //oSmtp->Password = _T("test");
  
  //If your server requires SSL connection 
  //oSmtp->SSL_init();
  //oSmtp->SSL_starttls = 0; 
  //oSmtp->ServerPort = 465;
  
  //If your server requires TLS connection 
  //oSmtp->SSL_init();
  //oSmtp->SSL_starttls = 1; 
  //oSmtp->ServerPort = 25;  
    
  oSmtp->FromAddr = _T( "test@adminsystem.net" );
  oSmtp->AddRecipient( _T("Support Team"), 
                         _T("support@adminsystem.net"), 0 );

  oSmtp->BodyFormat = 1;
  oSmtp->Subject = _T("Test");
  oSmtp->BodyText = _T("<html>..<body>Hello, this is a test....");
  oSmtp->AltBody = _T("Hello, this is a test");
  
  if( oSmtp->SendMail() == 0 )
    cout << "Message delivered!" << endl;
  else
    cout << (const TCHAR*)(oSmtp->GetLastErrDescription()) << endl;
}

See Also

BodyText Property
BodyFormat Property