SMTP Object

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

The SMTP object supports a lot of SMTP authentication methods, including OAuth 2.0 and NTLM). See AuthMethod property for details.

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 (legacy) or MailBee .NET Queue (modern) system. MailBee.NET Queue (needs .NET Framework) has more features than MailBee Message Queue and supports SSL.

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
AllowRefusedRecipients Lets MailBee tolerate rejected recipients during sending in case if at least one recipient gets accepted by the server.
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.
ISQueueIIS Gets or sets if the e-mail queue folder belongs to IIS SMTP service.
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.
MailFromDSN Optional DSN suffix for MAIL FROM command.
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.
RcptToDSN Optional DSN suffix for RCPT TO commands.
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.
SupportsDSN Indicates whether the SMTP server supports DSN (Delivery Status Nofitications).
SupportsStartTLS Indicates whether the SMTP server supports STARTTLS command.
TargetName The SPN of the server (only used with Kerberos authentication).
Timeout The timeout value in seconds.
ToAddr The e-mail addresses of the primary recipients.
UserDomain The name of the user domain on the SMTP server (only used with MS specific authentication types like NTLM).
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.
GetAcceptedRecipients Returns the comma-separated string which lists the e-mail addresses which have been accepted by the server during sending.
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.
GetRefusedRecipients Returns the comma-separated string which lists the e-mail addresses which have been rejected by the server during sending.
GetLastDataFromClient Gets the data chunk sent by the client during the last I/O operation.
GetLastDataFromServer Gets the data chunk received by the client from the server during the last I/O operation.
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.
OnReceiveData Fires when the client receives another data chunk from the server.
OnSendComplete Fires when the message has been sent.
OnSendData Fires when the client sends another data chunk to the server.
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:\Temp\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:\Temp\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-2024, AfterLogic Corporation. All rights reserved.