Ferrysoft

SMTP Module

Overview

The Ferrysoft SMTP Module is a client class to send emails to an SMTP server. The SMTP Module is provided in source code form (Visual Basic 2008/2010 compatible and Visual C# 2008/2010 compatible). It is intended for developers, to incorporate into their own applications, in order to provide SMTP client support to the application. The module can be used, royalty-free, by any individual or organisation that purchases the module. As the module is provided in source code form, it can be modified as necessary after purchase, provided that any derived module is not distributed, in source code form, to a third party. The module can be incorporated into a commercial product and sold to third parties, in compiled format, provided that the purpose of the commercial product is not simply to act as a wrapper for the SMTP Module.

Buy It

The SMTP Module is available for download in a password protected zip file. A royalty-free source code licence to use the SMTP Module can be purchased. On completion of the purchase, Ferrysoft will email the password of the protected zip file to the purchaser to enable the SMTP Module to be extracted for use.

The SMTP Module is priced in Pounds Sterling (GBP), US Dollars (USD) and Euros (EUR).

Ferrysoft SMTP Module Price PayPal
Royalty-free source code licence (GBP) £49
Royalty-free source code licence (USD) $99
Royalty-free source code licence (EUR) €75

Summary

The Ferrysoft SMTP Module is a wrapper class for the System.Net.Mail namespace. It has the following advantages over using the System.Net.Mail namespace natively:

  • Encapsulates most references to the System.Net.Mail namespace within the class.
  • Provides simple parameterised methods instead of having to use multiple namespace properties.
  • Provides an easy way of setting all email address fields of the message.
  • Provides an easy way of including alternate views with the message.
  • Provides an easy way of including attachments with the message.
  • Provides an easy way of sending the message.

Summary of methods provided by the class

The methods provided by the class are described in the following table.

Method Use
AppendAlternateView Used to append an alternate view to the email message. Alternate views allow the recipient's email client to display the email in an appropriate format according to the capabilities of the email client. For example, an email message could be sent in plain text format with an alternate view in HTML format. The recipient's email client would display the message in HTML format if it had the capability, otherwise it would display the message in plain text format.
AppendAttachment Used to append an attachment to the email message.
AppendBlindCarbonCopy Used to append an email address to the collection of email addresses in the Bcc: field of the email.
AppendCarbonCopy Used to append an email address to the collection of email addresses in the Cc: field of the email.
AppendInReplyTo Used to append a message-id to the In-Reply-To: field of the email.
AppendReferences Used to append a message-id to the References: field of the email.
AppendReplyTo Used to append an email address to the collection of email addresses in the Reply-To: field of the email. The AppendReplyTo method depends on the System.Net.Mail.MailMessage.ReplyToList property, which is only available with the .NET Framework 4 or later. By default, the active code of the AppendReplyTo method is commented out. This ensures that it compiles cleanly, regardless of the .NET Framework version in use. If the .NET Framework 4 or later is in use and the AppendReplyTo method is required then the code for that method should be uncommented to activate it, before compiling.
AppendTo Used to append an email address to the collection of email addresses in the To: field of the email.
Compose Used to set the email message level properties such as the subject and body of the message.
Send Used to send the email message to a pickup directory or an SMTP server, according to the parameters provided. The method provides the combined parameter list of the SendToPickupDirectory and SendToServer methods.
SendToPickupDirectory Used to send the email message to a pickup directory. The method allows the message to be sent to a specified pickup directory or the default IIS pickup directory.
SendToServer Used to send the email message to an SMTP server. The method allows the message to be sent to a specifed SMTP server. The variants of the method provide a full range of defaults.
SendUsingConfigSettings Used to send the email message to a pickup directory or an SMTP server, using settings contained in the application or machine configuration files.
SetFrom Used to set the From: field of the email. As with all methods related to email addresses, there are three variants of the method. The first accepts just an email address, for example "john.doe@example.com". The second accepts an email address and name, for example "john.doe@example.com" and "John Doe". The third accepts an additional parameter to specify the encoding of the email name.
SetMessageID Used to set the Message-ID: field of the email. As with all methods related to message-ids, there are two variants of the method. The first accepts a formatted message-id, for example "<CD0F1E2AD0954560A06A58FCDDC15200@example.com>". The second accepts a message-id in two component parts, for example "CD0F1E2AD0954560A06A58FCDDC15200" and "example.com".
SetReplyTo Used to set the Reply-To: field of the email. The SetReplyTo method depends on the System.Net.Mail.MailMessage.ReplyTo property, which is obsolete with the .NET Framework 4 and later. By default, the active code of the SetReplyTo method is commented out. This ensures that it compiles cleanly, regardless of the .NET Framework version in use. If the .NET Framework 3.5 or earlier is in use and the SetReplyTo method is required then the code for that method should be uncommented to activate it, before compiling.
SetSender Used to set the Sender: field of the email.

AppendAlternateView method

Syntax

Visual Basic
Public Sub AppendAlternateView( _
    ByVal AlternateView As System.Net.Mail.AlternateView)
C#
public void AppendAlternateView(
    System.Net.Mail.AlternateView AlternateView)

Parameters

AlternateView
An alternate view. See example for how to create an alternate view object.

AppendAttachment method

Syntax

Visual Basic
Public Sub AppendAttachment( _
    ByVal Attachment As System.Net.Mail.Attachment)
C#
public void AppendAttachment(
    System.Net.Mail.Attachment Attachment)

Parameters

Attachment
An attachment. See example for how to create an attachment object.

AppendBlindCarbonCopy methods

Syntax

Visual Basic
Public Sub AppendBlindCarbonCopy( _
    ByVal EmailAddress As String)

Public Sub AppendBlindCarbonCopy( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)

Public Sub AppendBlindCarbonCopy( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String, _
    ByVal EmailNameEncoding As System.Text.Encoding)
C#
public void AppendBlindCarbonCopy(
    string EmailAddress)

public void AppendBlindCarbonCopy(
    string EmailAddress,
    string EmailName)

public void AppendBlindCarbonCopy(
    string EmailAddress,
    string EmailName,
    System.Text.Encoding EmailNameEncoding)

Parameters

EmailAddress
The email address, for example "john.doe@example.com".
EmailName
The email name, for example "John Doe". Default is "".
EmailNameEncoding
The encoding of the email name. The parameter can be set to an encoding derived via System.Text.Encoding.GetEncoding or any of the following enumerations of System.Text.Encoding:
ASCII
BigEndianUnicode
Default
Unicode
UTF32
UTF7
UTF8

AppendCarbonCopy methods

Syntax

Visual Basic
Public Sub AppendCarbonCopy( _
    ByVal EmailAddress As String)

Public Sub AppendCarbonCopy( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)

Public Sub AppendCarbonCopy( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String, _
    ByVal EmailNameEncoding As System.Text.Encoding)
C#
public void AppendCarbonCopy(
    string EmailAddress)

public void AppendCarbonCopy(
    string EmailAddress,
    string EmailName)

public void AppendCarbonCopy(
    string EmailAddress,
    string EmailName,
    System.Text.Encoding EmailNameEncoding)

Parameters

EmailAddress
The email address, for example "john.doe@example.com".
EmailName
The email name, for example "John Doe". Default is "".
EmailNameEncoding
The encoding of the email name. The parameter can be set to an encoding derived via System.Text.Encoding.GetEncoding or any of the following enumerations of System.Text.Encoding:
ASCII
BigEndianUnicode
Default
Unicode
UTF32
UTF7
UTF8

AppendInReplyTo methods

Syntax

Visual Basic
Public Sub AppendInReplyTo( _
    ByVal MessageID As String)

Public Sub AppendInReplyTo( _
    ByVal LeftMessageID As String, _
    ByVal RightMessageID As String)
C#
public void AppendInReplyTo(
    string MessageID)

public void AppendInReplyTo(
    string LeftMessageID,
    string RightMessageID)

Parameters

MessageID
The message-id, for example "<CD0F1E2AD0954560A06A58FCDDC15200@example.com>".
LeftMessageID
The left-side component of the message-id, for example "CD0F1E2AD0954560A06A58FCDDC15200".
RightMessageID
The right-side component of the message-id, for example "example.com".

AppendReferences methods

Syntax

Visual Basic
Public Sub AppendReferences( _
    ByVal MessageID As String)

Public Sub AppendReferences( _
    ByVal LeftMessageID As String, _
    ByVal RightMessageID As String)
C#
public void AppendReferences(
    string MessageID)

public void AppendReferences(
    string LeftMessageID,
    string RightMessageID)

Parameters

MessageID
The message-id, for example "<CD0F1E2AD0954560A06A58FCDDC15200@example.com>".
LeftMessageID
The left-side component of the message-id, for example "CD0F1E2AD0954560A06A58FCDDC15200".
RightMessageID
The right-side component of the message-id, for example "example.com".

AppendReplyTo methods

Syntax

Visual Basic
Public Sub AppendReplyTo( _
    ByVal EmailAddress As String)

Public Sub AppendReplyTo( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)

Public Sub AppendReplyTo( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String, _
    ByVal EmailNameEncoding As System.Text.Encoding)
C#
public void AppendReplyTo(
    string EmailAddress)

public void AppendReplyTo(
    string EmailAddress,
    string EmailName)

public void AppendReplyTo(
    string EmailAddress,
    string EmailName,
    System.Text.Encoding EmailNameEncoding)

Parameters

EmailAddress
The email address, for example "john.doe@example.com".
EmailName
The email name, for example "John Doe". Default is "".
EmailNameEncoding
The encoding of the email name. The parameter can be set to an encoding derived via System.Text.Encoding.GetEncoding or any of the following enumerations of System.Text.Encoding:
ASCII
BigEndianUnicode
Default
Unicode
UTF32
UTF7
UTF8

AppendTo methods

Syntax

Visual Basic
Public Sub AppendTo( _
    ByVal EmailAddress As String)

Public Sub AppendTo( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)

Public Sub AppendTo( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String, _
    ByVal EmailNameEncoding As System.Text.Encoding)
C#
public void AppendTo(
    string EmailAddress)

public void AppendTo(
    string EmailAddress,
    string EmailName)

public void AppendTo(
    string EmailAddress,
    string EmailName,
    System.Text.Encoding EmailNameEncoding)

Parameters

EmailAddress
The email address, for example "john.doe@example.com".
EmailName
The email name, for example "John Doe". Default is "".
EmailNameEncoding
The encoding of the email name. The parameter can be set to an encoding derived via System.Text.Encoding.GetEncoding or any of the following enumerations of System.Text.Encoding:
ASCII
BigEndianUnicode
Default
Unicode
UTF32
UTF7
UTF8

Compose methods

Syntax

Visual Basic
Public Sub Compose( _
    ByVal MessageSubject As String, _
    ByVal MessageBody As String)

Public Sub Compose( _
    ByVal MessageSubject As String, _
    ByVal MessageBody As String, _
    ByVal MessageSubjectEncoding As System.Text.Encoding, _
    ByVal MessageBodyEncoding As System.Text.Encoding, _
    ByVal MessageIsBodyHtml As Boolean, _
    ByVal MessagePriority As System.Net.Mail.MailPriority, _
    ByVal MessageDeliveryNotificationOptions As _
        System.Net.Mail.DeliveryNotificationOptions)
C#
public void Compose(
    string MessageSubject,
    string MessageBody)

public void Compose(
    string MessageSubject,
    string MessageBody,
    System.Text.Encoding MessageSubjectEncoding,
    System.Text.Encoding MessageBodyEncoding,
    bool MessageIsBodyHtml,
    System.Net.Mail.MailPriority MessagePriority,
    System.Net.Mail.DeliveryNotificationOptions MessageDeliveryNotificationOptions)

Parameters

MessageSubject
The text for the Subject: property, for example "Email test subject".
MessageBody
The text of the message, for example "Email test message".
MessageSubjectEncoding
The encoding of the subject. The parameter can be set to an encoding derived via System.Text.Encoding.GetEncoding or any of the following enumerations of System.Text.Encoding:
ASCII
BigEndianUnicode
Default
Unicode
UTF32
UTF7
UTF8 (default)
MessageBodyEncoding
The encoding of the message. The parameter can be set to an encoding derived via System.Text.Encoding.GetEncoding or any of the following enumerations of System.Text.Encoding:
ASCII
BigEndianUnicode
Default
Unicode
UTF32
UTF7
UTF8 (default)
MessageIsBodyHtml
Indicates whether the body of the message is in HTML format. The parameter can be either of the following:
True - HTML format
False - Not HTML format (default)
MessagePriority
The priority of the message. The parameter can be set to any of the following enumerations of System.Net.Mail.MailPriority:
High
Low
Normal (default)
MessageDeliveryNotificationOptions
The delivery notification options of the message. The parameter can be set to any of the following enumerations of System.Net.Mail.DeliveryNotificationOptions:
Delay
Never
None (default)
OnFailure
OnSuccess

Send method

Syntax

Visual Basic
Public Sub Send( _
    ByVal Delivery As Ferrysoft.Smtp.DeliveryTo, _
    ByVal Server As String, _
    ByVal Port As Integer, _
    ByVal Encrypted As Boolean, _
    ByVal Timeout As Integer, _
    ByVal Authentication As Ferrysoft.Smtp.AuthenticationCredentials, _
    ByVal Username As String, _
    ByVal Password As String, _
    ByVal Domain As String, _
    ByVal PickupDirectory As String)
C#
public void Send(
    Ferrysoft.Smtp.DeliveryTo Delivery,
    string Server,
    int Port,
    bool Encrypted,
    int Timeout,
    Ferrysoft.Smtp.AuthenticationCredentials Authentication,
    string Username,
    string Password,
    string Domain,
    string PickupDirectory)

Parameters

Delivery
The delivery target (server or pickup directory) to send to. The parameter can be set to any of the following enumerations of Ferrysoft.Smtp.DeliveryTo:
SpecificSmtpServer - Delivery is to the server specified by the Server parameter.
SpecificPickupDirectory - Delivery is to a directory specified by the PickupDirectory parameter.
DefaultPickupDirectory - Delivery is to the default IIS pickup directory.
Server
The server name of the SMTP Server. For example, the fictitious server "smtp.example.com". The default is "localhost".
Port
The server port number. The default is 25.
Encrypted
Indicates whether the server requires an encrypted connection. The parameter can be either of the following:
True - Requires an encrypted connection
False - Does not require an encrypted connection
Timeout
The server connection timeout in seconds.
Authentication
The authentication credentials to use for the server connection. The parameter can be set to any of the following enumerations of Ferrysoft.Smtp.AuthenticationCredentials:
None - No authentication credentials are required for the connection to the server.
Specific - The specified username, password and domain are used to create the authentication credentials for the connection to the server.
Default - The user's default credentials are used to create the authentication credentials for the connection to the server.
Username
The username if the Authentication parameter is set to Ferrysoft.Smtp.AuthenticationCredentials.Specific.
Password
The password if the Authentication parameter is set to Ferrysoft.Smtp.AuthenticationCredentials.Specific.
Domain
The domain if the Authentication parameter is set to Ferrysoft.Smtp.AuthenticationCredentials.Specific. The domain can be set to blank if username and password are sufficient to establish the authentication credentials.
PickupDirectory
The pickup directory path if the Delivery parameter is set to Ferrysoft.Smtp.DeliveryTo.SpecificPickupDirectory. If the pickup directory path is blank then the default IIS pickup directory is used.

SendToPickupDirectory methods

Syntax

Visual Basic
Public Sub SendToPickupDirectory()

Public Sub SendToPickupDirectory( _
    ByVal PickupDirectory As String)
C#
public void SendToPickupDirectory()

public void SendToPickupDirectory(
    string PickupDirectory)

Parameters

PickupDirectory
The pickup directory path. If the pickup directory path is blank then the default IIS pickup directory is used. The default is blank.

SendToServer methods

Syntax

Visual Basic
Public Sub SendToServer()

Public Sub SendToServer( _
    ByVal Server As String)

Public Sub SendToServer( _
    ByVal Server As String, _
    ByVal Port As Integer)

Public Sub SendToServer( _
    ByVal Server As String, _
    ByVal Port As Integer, _
    ByVal Encrypted As Boolean)

Public Sub SendToServer( _
    ByVal Server As String, _
    ByVal Port As Integer, _
    ByVal Encrypted As Boolean, _
    ByVal Timeout As Integer)

Public Sub SendToServer( _
    ByVal Server As String, _
    ByVal Port As Integer, _
    ByVal Encrypted As Boolean, _
    ByVal Timeout As Integer, _
    ByVal Authentication As Ferrysoft.Smtp.AuthenticationCredentials)

Public Sub SendToServer( _
    ByVal Server As String, _
    ByVal Port As Integer, _
    ByVal Encrypted As Boolean, _
    ByVal Timeout As Integer, _
    ByVal Authentication As Ferrysoft.Smtp.AuthenticationCredentials, _
    ByVal Username As String, _
    ByVal Password As String)

Public Sub SendToServer( _
    ByVal Server As String, _
    ByVal Port As Integer, _
    ByVal Encrypted As Boolean, _
    ByVal Timeout As Integer, _
    ByVal Authentication As Ferrysoft.Smtp.AuthenticationCredentials, _
    ByVal Username As String, _
    ByVal Password As String, _
    ByVal Domain As String)
C#
public void SendToServer()

public void SendToServer(
    string Server)

public void SendToServer(
    string Server,
    int Port)

public void SendToServer(
    string Server,
    int Port,
    bool Encrypted)

public void SendToServer(
    string Server,
    int Port,
    bool Encrypted,
    int Timeout)

public void SendToServer(
    string Server,
    int Port,
    bool Encrypted,
    int Timeout,
    Ferrysoft.Smtp.AuthenticationCredentials Authentication)

public void SendToServer(
    string Server,
    int Port,
    bool Encrypted,
    int Timeout,
    Ferrysoft.Smtp.AuthenticationCredentials Authentication,
    string Username,
    string Password)

public void SendToServer(
    string Server,
    int Port,
    bool Encrypted,
    int Timeout,
    Ferrysoft.Smtp.AuthenticationCredentials Authentication,
    string Username,
    string Password,
    string Domain)

Parameters

Server
The server name of the SMTP Server. For example, the fictitious server "smtp.example.com". The default is "localhost".
Port
The server port number. The default is 25.
Encrypted
Indicates whether the server requires an encrypted connection. The parameter can be either of the following:
True - Requires an encrypted connection
False - Does not require an encrypted connection
The default is False.
Timeout
The server connection timeout in seconds. The default is 30.
Authentication
The authentication credentials to use for the server connection. The parameter can be set to any of the following enumerations of Ferrysoft.Smtp.AuthenticationCredentials:
None - No authentication credentials are required for the connection to the server.
Specific - The specified username, password and domain are used to create the authentication credentials for the connection to the server.
Default - The user's default credentials are used to create the authentication credentials for the connection to the server.
The default is None.
Username
The username if the Authentication parameter is set to Ferrysoft.Smtp.AuthenticationCredentials.Specific. The default is blank.
Password
The password if the Authentication parameter is set to Ferrysoft.Smtp.AuthenticationCredentials.Specific. The default is blank.
Domain
The domain if the Authentication parameter is set to Ferrysoft.Smtp.AuthenticationCredentials.Specific. The domain can be set to blank if username and password are sufficient to establish the authentication credentials. The default is blank.

SendUsingConfigSettings method

Syntax

Visual Basic
Public Sub SendUsingConfigSettings()
C#
public void SendUsingConfigSettings()

The following example shows an application configuration file with the mailSettings section specifying the settings for the use of the SendUsingConfigSettings method.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.net>
        <mailSettings>
            <smtp deliveryMethod="Network">
                <network
                    host="smtp.example.com"
                    port="25"
                    defaultCredentials="false"
                    userName="myusername"
                    password="mypassword" />
                <specifiedPickupDirectory
                    pickupDirectoryLocation="" />
            </smtp>
        </mailSettings>
    </system.net>
</configuration>

SetFrom methods

Syntax

Visual Basic
Public Sub SetFrom( _
    ByVal EmailAddress As String)

Public Sub SetFrom( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)

Public Sub SetFrom( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String, _
    ByVal EmailNameEncoding As System.Text.Encoding)
C#
public void SetFrom(
    string EmailAddress)

public void SetFrom(
    string EmailAddress,
    string EmailName)

public void SetFrom(
    string EmailAddress,
    string EmailName,
    System.Text.Encoding EmailNameEncoding)

Parameters

EmailAddress
The email address, for example "john.doe@example.com".
EmailName
The email name, for example "John Doe". Default is "".
EmailNameEncoding
The encoding of the email name. The parameter can be set to an encoding derived via System.Text.Encoding.GetEncoding or any of the following enumerations of System.Text.Encoding:
ASCII
BigEndianUnicode
Default
Unicode
UTF32
UTF7
UTF8

SetMessageID methods

Syntax

Visual Basic
Public Sub SetMessageID( _
    ByVal MessageID As String)

Public Sub SetMessageID( _
    ByVal LeftMessageID As String, _
    ByVal RightMessageID As String)
C#
public void SetMessageID(
    string MessageID)

public void SetMessageID(
    string LeftMessageID,
    string RightMessageID)

Parameters

MessageID
The message-id, for example "<CD0F1E2AD0954560A06A58FCDDC15200@example.com>".
LeftMessageID
The left-side component of the message-id, for example "CD0F1E2AD0954560A06A58FCDDC15200".
RightMessageID
The right-side component of the message-id, for example "example.com".

SetReplyTo methods

Syntax

Visual Basic
Public Sub SetReplyTo( _
    ByVal EmailAddress As String)

Public Sub SetReplyTo( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)

Public Sub SetReplyTo( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String, _
    ByVal EmailNameEncoding As System.Text.Encoding)
C#
public void SetReplyTo(
    string EmailAddress)

public void SetReplyTo(
    string EmailAddress,
    string EmailName)

public void SetReplyTo(
    string EmailAddress,
    string EmailName,
    System.Text.Encoding EmailNameEncoding)

Parameters

EmailAddress
The email address, for example "john.doe@example.com".
EmailName
The email name, for example "John Doe". Default is "".
EmailNameEncoding
The encoding of the email name. The parameter can be set to an encoding derived via System.Text.Encoding.GetEncoding or any of the following enumerations of System.Text.Encoding:
ASCII
BigEndianUnicode
Default
Unicode
UTF32
UTF7
UTF8

SetSender methods

Syntax

Visual Basic
Public Sub SetSender( _
    ByVal EmailAddress As String)

Public Sub SetSender( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)

Public Sub SetSender( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String, _
    ByVal EmailNameEncoding As System.Text.Encoding)
C#
public void SetSender(
    string EmailAddress)

public void SetSender(
    string EmailAddress,
    string EmailName)

public void SetSender(
    string EmailAddress,
    string EmailName,
    System.Text.Encoding EmailNameEncoding)

Parameters

EmailAddress
The email address, for example "john.doe@example.com".
EmailName
The email name, for example "John Doe". Default is "".
EmailNameEncoding
The encoding of the email name. The parameter can be set to an encoding derived via System.Text.Encoding.GetEncoding or any of the following enumerations of System.Text.Encoding:
ASCII
BigEndianUnicode
Default
Unicode
UTF32
UTF7
UTF8

Example Use

The code below shows an example of how to use the SMTP client class.

Visual Basic
Dim SmtpClient As Ferrysoft.Smtp.Client
Dim Attachment As System.Net.Mail.Attachment
Dim AlternateView As System.Net.Mail.AlternateView
Dim LinkedResource As System.Net.Mail.LinkedResource
Dim ContentType As System.Net.Mime.ContentType
'
'   Create the SMTP client.
'
SmtpClient = New Ferrysoft.Smtp.Client()
'
'   This example sends a plain text message.
'
SmtpClient.Compose("Example 1 message subject", _
    "Example plain text message")
SmtpClient.SetFrom("jane.doe@example.com")
SmtpClient.AppendTo("john.doe@example.com")
SmtpClient.SendUsingConfigSettings()
'
'   This example sends an HTML message with
'   multiple addresses for To:, Cc: and Bcc:.
'   It also sets the Sender: field and
'   sends the message with high priority.
'
SmtpClient.Compose("Example 2 message subject", _
    "<html><body>Example <b>HTML</b> message</body></html>", _
    System.Text.Encoding.UTF8, _
    System.Text.Encoding.UTF8, _
    True, _
    System.Net.Mail.MailPriority.High, _
    System.Net.Mail.DeliveryNotificationOptions.None)
SmtpClient.SetFrom("jane.doe@example.com", "Jane Doe")
SmtpClient.SetSender("gary.doe@example.com", "Gary Doe")
SmtpClient.AppendTo("john.doe@example.com", "John Doe")
SmtpClient.AppendTo("andy.doe@example.com")
SmtpClient.AppendTo("bill.doe@example.com", "Bill Doe")
SmtpClient.AppendCarbonCopy("cloe.doe@example.com", "Cloe Doe")
SmtpClient.AppendCarbonCopy("david.doe@example.com")
SmtpClient.AppendBlindCarbonCopy("eileen.doe@example.com")
SmtpClient.AppendBlindCarbonCopy("fred.doe@example.com", "Fred Doe")
SmtpClient.SendToServer("smtp.example.com", _
    25, _
    False, _
    30, _
    Ferrysoft.Smtp.AuthenticationCredentials.Specific, _
    "myusername", _
    "mypassword")
'
'   This example sends a message with both
'   plain text and HTML views. This allows the
'   recipient to see either a plain text view or
'   an HTML view depending on the capabilities of
'   the recipient's email client.
'   The plain text view is composed in the message
'   body and the HTML view is attached as an
'   alternate view.
'   The message requests delivery notification on
'   success.
'   The message also has three attachments.
'
SmtpClient.Compose("Example 3 message subject", _
    "Example plain text message", _
    System.Text.Encoding.UTF8, _
    System.Text.Encoding.UTF8, _
    False, _
    System.Net.Mail.MailPriority.Normal, _
    System.Net.Mail.DeliveryNotificationOptions.OnSuccess)
SmtpClient.SetFrom("jane.doe@example.com", "Jane Doe")
SmtpClient.AppendTo("john.doe@example.com", "John Doe")
'
'   Append an alternate view in HTML format.
'
AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString( _
    "<html><body>Example <b>HTML</b> message</body></html>", _
    System.Text.Encoding.UTF8, _
    System.Net.Mime.MediaTypeNames.Text.Html)
SmtpClient.AppendAlternateView(AlternateView)
'
'   Attach a Microsoft Word document.
'
Attachment = New System.Net.Mail.Attachment( _
    "C:\Test\Test1.docx", "application/msword")
Attachment.ContentDisposition.DispositionType = _
    System.Net.Mime.DispositionTypeNames.Attachment
SmtpClient.AppendAttachment(Attachment)
'
'   Attach a text file. Note that a ContentType
'   is used to prepare the attachment so that
'   the MediaType and CharSet can be explicitly
'   specified.
'
ContentType = New System.Net.Mime.ContentType()
ContentType.MediaType = System.Net.Mime.MediaTypeNames.Text.Plain
ContentType.CharSet = System.Text.Encoding.UTF8.WebName
Attachment = New System.Net.Mail.Attachment( _
    "C:\Test\Test1.txt", ContentType)
Attachment.ContentDisposition.DispositionType = _
    System.Net.Mime.DispositionTypeNames.Attachment
SmtpClient.AppendAttachment(Attachment)
'
'   Attach a text file created from a string.
'
Attachment = System.Net.Mail.Attachment.CreateAttachmentFromString( _
    "This is a text attachment", _
    "Test2.txt", _
    System.Text.Encoding.UTF8, _
    System.Net.Mime.MediaTypeNames.Text.Plain)
Attachment.ContentDisposition.DispositionType = _
    System.Net.Mime.DispositionTypeNames.Attachment
SmtpClient.AppendAttachment(Attachment)
SmtpClient.SendToServer("smtp.example.com")
'
'   This example sends a message with both
'   plain text and HTML views.
'   The plain text view is composed in the message
'   body and the HTML view is attached as an
'   alternate view.
'   The HTML alternate view has three embedded images
'   associated with it as linked resources.
'
SmtpClient.Compose("Example 4 message subject", _
    "Example plain text message", _
    System.Text.Encoding.UTF8, _
    System.Text.Encoding.UTF8, _
    False, _
    System.Net.Mail.MailPriority.Normal, _
    System.Net.Mail.DeliveryNotificationOptions.None)
SmtpClient.SetFrom("jane.doe@example.com", "Jane Doe")
SmtpClient.AppendTo("john.doe@example.com", "John Doe")
'
'   Append an alternate view in HTML format.
'
AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString( _
    "<html><body>" & _
    "<p>Example <b>HTML</b> message</p>" & _
    "<p>Image 1: <img src=""cid:image1""/></p>" & _
    "<p>Image 2: <img src=""cid:image2""/></p>" & _
    "<p>Image 3: <img src=""cid:image3""/></p>" & _
    "</body></html>", _
    System.Text.Encoding.UTF8, _
    System.Net.Mime.MediaTypeNames.Text.Html)
LinkedResource = New System.Net.Mail.LinkedResource("C:\Test\Image1.gif")
LinkedResource.ContentId = "image1"
LinkedResource.ContentType.Name = "Image1.gif"
AlternateView.LinkedResources.Add(LinkedResource)
LinkedResource = New System.Net.Mail.LinkedResource("C:\Test\Image2.gif", _
    System.Net.Mime.MediaTypeNames.Image.Gif)
LinkedResource.ContentId = "image2"
LinkedResource.ContentType.Name = "Image2.gif"
AlternateView.LinkedResources.Add(LinkedResource)
ContentType = New System.Net.Mime.ContentType()
ContentType.MediaType = System.Net.Mime.MediaTypeNames.Image.Gif
ContentType.CharSet = System.Text.Encoding.UTF8.WebName
LinkedResource = New System.Net.Mail.LinkedResource("C:\Test\Image3.gif", ContentType)
LinkedResource.ContentId = "image3"
LinkedResource.ContentType.Name = "Image3.gif"
AlternateView.LinkedResources.Add(LinkedResource)
SmtpClient.AppendAlternateView(AlternateView)
SmtpClient.SendToServer("smtp.example.com")
C#
Ferrysoft.Smtp.Client SmtpClient;
System.Net.Mail.Attachment Attachment;
System.Net.Mail.AlternateView AlternateView;
System.Net.Mail.LinkedResource LinkedResource;
System.Net.Mime.ContentType ContentType;
//
//  Create the SMTP client.
//
SmtpClient = new Ferrysoft.Smtp.Client();
//
//  This example sends a plain text message.
//
SmtpClient.Compose("Example 1 message subject",
    "Example plain text message");
SmtpClient.SetFrom("jane.doe@example.com");
SmtpClient.AppendTo("john.doe@example.com");
SmtpClient.SendUsingConfigSettings();
//
//  This example sends an HTML message with
//  multiple addresses for To:, Cc: and Bcc:.
//  It also sets the Sender: field and
//  sends the message with high priority.
//
SmtpClient.Compose("Example 2 message subject",
    "<html><body>Example <b>HTML</b> message</body></html>",
    System.Text.Encoding.UTF8,
    System.Text.Encoding.UTF8,
    true,
    System.Net.Mail.MailPriority.High,
    System.Net.Mail.DeliveryNotificationOptions.None);
SmtpClient.SetFrom("jane.doe@example.com", "Jane Doe");
SmtpClient.SetSender("gary.doe@example.com", "Gary Doe");
SmtpClient.AppendTo("john.doe@example.com", "John Doe");
SmtpClient.AppendTo("andy.doe@example.com");
SmtpClient.AppendTo("bill.doe@example.com", "Bill Doe");
SmtpClient.AppendCarbonCopy("cloe.doe@example.com", "Cloe Doe");
SmtpClient.AppendCarbonCopy("david.doe@example.com");
SmtpClient.AppendBlindCarbonCopy("eileen.doe@example.com");
SmtpClient.AppendBlindCarbonCopy("fred.doe@example.com", "Fred Doe");
SmtpClient.SendToServer("smtp.example.com",
    25,
    false,
    30,
    Ferrysoft.Smtp.AuthenticationCredentials.Specific,
    "myusername",
    "mypassword");
//
//  This example sends a message with both
//  plain text and HTML views. This allows the
//  recipient to see either a plain text view or
//  an HTML view depending on the capabilities of
//  the recipient's email client.
//  The plain text view is composed in the message
//  body and the HTML view is attached as an
//  alternate view.
//  The message requests delivery notification on
//  success.
//  The message also has three attachments.
//
SmtpClient.Compose("Example 3 message subject",
    "Example plain text message",
    System.Text.Encoding.UTF8,
    System.Text.Encoding.UTF8,
    false,
    System.Net.Mail.MailPriority.Normal,
    System.Net.Mail.DeliveryNotificationOptions.OnSuccess);
SmtpClient.SetFrom("jane.doe@example.com", "Jane Doe");
SmtpClient.AppendTo("john.doe@example.com", "John Doe");
//
//  Append an alternate view in HTML format.
//
AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(
    "<html><body>Example <b>HTML</b> message</body></html>",
    System.Text.Encoding.UTF8,
    System.Net.Mime.MediaTypeNames.Text.Html);
SmtpClient.AppendAlternateView(AlternateView);
//
//  Attach a Microsoft Word document.
//
Attachment = new System.Net.Mail.Attachment(
    "C:\\Test\\Test1.docx", "application/msword");
Attachment.ContentDisposition.DispositionType =
    System.Net.Mime.DispositionTypeNames.Attachment;
SmtpClient.AppendAttachment(Attachment);
//
//  Attach a text file. Note that a ContentType
//  is used to prepare the attachment so that
//  the MediaType and CharSet can be explicitly
//  specified.
//
ContentType = new System.Net.Mime.ContentType();
ContentType.MediaType = System.Net.Mime.MediaTypeNames.Text.Plain;
ContentType.CharSet = System.Text.Encoding.UTF8.WebName;
Attachment = new System.Net.Mail.Attachment(
    "C:\\Test\\Test1.txt", ContentType);
Attachment.ContentDisposition.DispositionType =
    System.Net.Mime.DispositionTypeNames.Attachment;
SmtpClient.AppendAttachment(Attachment);
//
//  Attach a text file created from a string.
//
Attachment = System.Net.Mail.Attachment.CreateAttachmentFromString(
    "This is a text attachment",
    "Test2.txt",
    System.Text.Encoding.UTF8,
    System.Net.Mime.MediaTypeNames.Text.Plain);
Attachment.ContentDisposition.DispositionType =
    System.Net.Mime.DispositionTypeNames.Attachment;
SmtpClient.AppendAttachment(Attachment);
SmtpClient.SendToServer("smtp.example.com");
//
//  This example sends a message with both
//  plain text and HTML views.
//  The plain text view is composed in the message
//  body and the HTML view is attached as an
//  alternate view.
//  The HTML alternate view has three embedded images
//  associated with it as linked resources.
//
SmtpClient.Compose("Example 4 message subject",
    "Example plain text message",
    System.Text.Encoding.UTF8,
    System.Text.Encoding.UTF8,
    false,
    System.Net.Mail.MailPriority.Normal,
    System.Net.Mail.DeliveryNotificationOptions.None);
SmtpClient.SetFrom("jane.doe@example.com", "Jane Doe");
SmtpClient.AppendTo("john.doe@example.com", "John Doe");
//
//  Append an alternate view in HTML format.
//
AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(
    "<html><body>" +
    "<p>Example <b>HTML</b> message</p>" +
    "<p>Image 1: <img src=\"cid:image1\"/></p>" +
    "<p>Image 2: <img src=\"cid:image2\"/></p>" +
    "<p>Image 3: <img src=\"cid:image3\"/></p>" +
    "</body></html>",
    System.Text.Encoding.UTF8,
    System.Net.Mime.MediaTypeNames.Text.Html);
LinkedResource = new System.Net.Mail.LinkedResource("C:\\Test\\Image1.gif");
LinkedResource.ContentId = "image1";
LinkedResource.ContentType.Name = "Image1.gif";
AlternateView.LinkedResources.Add(LinkedResource);
LinkedResource = new System.Net.Mail.LinkedResource("C:\\Test\\Image2.gif",
    System.Net.Mime.MediaTypeNames.Image.Gif);
LinkedResource.ContentId = "image2";
LinkedResource.ContentType.Name = "Image2.gif";
AlternateView.LinkedResources.Add(LinkedResource);
ContentType = new System.Net.Mime.ContentType();
ContentType.MediaType = System.Net.Mime.MediaTypeNames.Image.Gif;
ContentType.CharSet = System.Text.Encoding.UTF8.WebName;
LinkedResource = new System.Net.Mail.LinkedResource("C:\\Test\\Image3.gif", ContentType);
LinkedResource.ContentId = "image3";
LinkedResource.ContentType.Name = "Image3.gif";
AlternateView.LinkedResources.Add(LinkedResource);
SmtpClient.AppendAlternateView(AlternateView);
SmtpClient.SendToServer("smtp.example.com");