SMTP Object

You can use the SMTP object to compose and send single and bulk e-mails.

The SMTP object uses the Message object as a source of the e-mail to be sent. Thus, all the functionality of the Message object can be used with the SMTP object too.

The SMTP object can also send e-mails stored on disk as files (RelayMessage method). For quick sending large amounts of e-mails, message queuing option is available through IIS SMTP pickup folder or external MailBee Message Queue system.

SMTP.Message property specifies the Message object which represents the e-mail to be sent. To compose the message, you must set properties of this Message object. For example, you can use the code below to specify the message subject:

objSMTP.Message.Subject = "Meeting request"

The SMTP object includes several methods and properties which allow shorter syntax for setting main attributes of the message. For example, the code below produces exactly the same result as the code above:

objSMTP.Subject = "Meeting request"

Syntax

SMTP.property|method

 

Properties
AltBodyEncoding Specifies which encoding method to use for the message alternative body.
AltBodyText Contains alternative plain-text body of the message if the primary body is HTML-formatted.
AuthMethod Specifies the authentication method to use when connecting to the SMTP server.
BCCAddr The e-mail addresses of the blind-carbon-copy recipients.
BodyEncoding Specifies which encoding method to use for the message primary body.
BodyFormat Indicates the primary body format: Plain-Text, HTML, etc.
BodyText The primary body text.
Busy Indicates whether the SMTP object is in the progress of sending or receiving data.
CCAddr The e-mail addresses of the carbon-copy recipients.
Charset Specifies the charset that was used for composing the message body.
ClientRequest Returns the last command string sent to the SMTP server.
Connected Indicates whether the SMTP session is active.
Domain Specifies the sender's domain. Not required by most of SMTP servers.
Enable8bitEncoding Indicates whether 8bit characters are permitted in the message body.
EnableEvents Specifies whether the SMTP object will handle and fire events.
EnableLogging Specifies whether the SMTP object must log the SMTP session into a file.
ErrCode Completion status of the last command.
ErrDesc Contains textual error description if the last command has completed with an error.
FromAddr The e-mail address of the sender.
IsError Indicates whether the last command has completed with errors.
Licensed Indicates whether valid license key has been assigned to the SMTP object.
LicenseKey Sets the license key to be used with the SMTP object.
LogFilePath Sets filename of the SMTP session log file.
Message Specifies the Message object which represents the e-mail to be sent.
Password The password of the user account on the SMTP server, if SMTP authentication is used.
PortNumber The port number of the SMTP service on the server. Defaults to 25.
ServerName The SMTP server name.
ServerResponse Returns the string that contains the entire last reply from the SMTP server.
SSL Specifies the SSL object to be used to establish secure TLS connection with the SMTP server.
Subject The subject of the message.
Timeout The timeout value in seconds.
ToAddr The e-mail addresses of the primary recipients.
UserName The name of the user account on the SMTP server, if SMTP authentication is used.
Methods
Abort Aborts current operation and immediately closes the SMTP session.
AddAttachment Attaches a file to the message.
AddHeader Adds custom header to the message.
ClearLog Clears the SMTP session log file.
Connect Connects to the SMTP server, and authenticates the sender if SMTP authentication is used.
Disconnect Disconnects from the SMTP server.
EncodeHeaderText Encodes a string in the specified charset.
ExecuteCommand Sends specified string of data to the SMTP server.
GetRelayServerFromEmailAddress Gets the host name of the domain willing to accept the mails for the specified e-mail address or an empty string if error occurred.
ImportAltBodyText Loads the specified file contents into the message alternative body.
ImportBodyText Loads the specified file contents into the message primary body and, optionally, scans the loaded HTML body for embedded objects and appends them as attachments.
MakeAltBody Creates the alternative plain-text body from the current value of the HTML body.
RelayMessage Relays the message stored as disk file to the specified recipients.
ResetMessage Resets the Message object associated with the SMTP object.
ResolveHostName Extracts the IP address of the specified host name.
Send Sends the message to the SMTP server.
SendEx Sends the message to the SMTP server, and allows you to override e-mail addresses of the sender and the recipients specified in the message.
SendToQueue Submits the message to IIS SMTP service or MailBee Message Queue system for delivery.
SendToQueueEx Submits the message to IIS SMTP service or MailBee Message Queue system for delivery, and allows you to override e-mail addresses of the sender and the recipients specified in the message.
Events
OnMessageReady Fires when the message data has been prepared for sending.
OnSendComplete Fires when the message has been sent.
OnSendProgress Fires when new portion of the message data has been sent.
OnSendStart Fires when the SMTP object has got ready to send the message to the SMTP server.

 

Remarks

During the development, it's recommended to enable logging the SMTP session into a file by setting EnableLogging and LogFilePath properties. The log file allows you to discover typical problems quickly and easily.

You can find more information on typical problems resolution in Troubleshooting section of the SMTP samples.

 

Example

The following example creates and sends an HTML-formatted message with an attachment. SMTP Authentication is enabled. SMTP session log is written into "C:\smtp_log.txt" file.
Dim objSMTP

' Using Visual Basic to create object
Set objSMTP = CreateObject("MailBee.SMTP")

' Using ASP to create object
' Set objSMTP = Server.CreateObject("MailBee.SMTP")
'
' In ASP, use Response.Write instead of MsgBox

' Enable logging SMTP session into a file
objSMTP.EnableLogging = True
objSMTP.LogFilePath = "C:\smtp_log.txt"
objSMTP.ClearLog

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

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

' Set SMTP Authentication method and
' user credentials
objSMTP.AuthMethod = 2
objSMTP.UserName = "jdoe"
objSMTP.Password = "secret"

' Set headers
objSMTP.Message.FromAddr = "John Doe <jdoe@mydomain.com>"
objSMTP.Message.ToAddr = "Bill Smith <b.smith@hisdomain.com>"
objSMTP.Message.Subject = "Question"

' Set HTML body
objSMTP.Message.BodyFormat = 1
objSMTP.Message.BodyText = "<html>How are <i>you</i>?</html>"

' Send message
If objSMTP.Send Then
  ' Succeeded!!
  MsgBox "Sent successfully"
Else
  ' Failed...
  MsgBox "Error #" & objSMTP.ErrCode & _
    ", Last server reply:" & objSMTP.ServerResponse
End If

' Close the connection
objSMTP.Disconnect

 

See Also

Message Object

 


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