PowerTCP Mail for .NET
Smtp Class
Members  Example 




Integrates Simple Mail Transfer Protocol (SMTP) functionality into any .NET application, allowing applications to easily send Internet mail.
Object Model
Smtp ClassTcpBase ClassDeliveryStatusNotification ClassSmtpSession Class
Syntax
Public Class Smtp 
   Inherits MailBase
Dim instance As Smtp
public class Smtp : MailBase 
public __gc class Smtp : public MailBase 
public ref class Smtp : public MailBase 
Remarks

The Smtp component sends Internet mail. It is feature-rich and flexible, and includes functionality not found in the .NET Platform such as multiple authentication techniques, proxy support, Stream support, access to the TCP connection, debugging features and more.

Using the Smtp Component

A short description of common usage follows. See the "Code Examples" topic for examples in C# and VB.

Session Management: Authentication is automatic. Close terminates the connection.

Sends Basic Mail: Send(String,String,String,String) provides a high-level method to send mail with one line of code.

Sends Advanced Mail: Send(MailMessage) encodes and sends the referenced MailMessage, allowing unprecedented ability to create any email message, no matter how complex the structure!

Sends Encoded Mail: Send(Stream,String,String) sends previously encoded email.

"On-the-fly" encoding: All MailMessage parts are encoded on-the-fly and streamed to the socket, minimizing the memory/disk footprint.

Displaying Progress: Progress provides progress updates while uploading.

Viewing SMTP Protocol Communications: The Smtp.Connection.Log event provides access to all commands and data sent over the TCP connection.

Control connection: Connection exposes the TCP connection, allowing access to low-level properties and methods. Can be used to view TCP-level properties, such as the local and remote IP address.

Sending commands: Any command (including proprietary commands) can be sent/received using Connection.Write() and Connection.Read().

Example
Uses the Smtp component to send a text message with an attachment.
private void sendMail(object sender)
{
    //Create message to send
    MailMessage message = new MailMessage();
    message.To = toAddress;
    message.From = fromAddress;
    message.Subject = "File Attached";
    message.Text = "Please see the attached file.";

    //Add the attachment
    message.Attachments.Add(new Attachment(Application.StartupPath + "\\myImage.jpg"));

    //Set session parameters
    smtp1.Session.RemoteEndPoint = 
        new Dart.Mail.IPEndPoint(myMailServer, Smtp.GetDefaultPort(smtp1.Session));
    smtp1.Session.Username = myUsername;
    smtp1.Session.Password = myPassword;

    //Send message
    smtp1.Send(message);

    //Logout gracefully
    smtp1.Close();
}

private void smtp1_Progress(object sender, SmtpProgressEventArgs e)
{
    //Update progress bar as message is sent
    progressBar1.Value = (e.Final) ? 0 : (int)((e.Position * 100) / e.Length);
}
Private Sub sendMail(ByVal sender As Object)
    'Create message to send
    Dim message As New MailMessage()
    message.To = toAddress
    message.From = fromAddress
    message.Subject = "File Attached"
    message.Text = "Please see the attached file."

    'Add the attachment
    message.Attachments.Add(New Attachment(Application.StartupPath & "\myImage.jpg"))

    'Set session parameters
    smtp1.Session.RemoteEndPoint = New Dart.Mail.IPEndPoint(myMailServer, Smtp.GetDefaultPort(smtp1.Session))
    smtp1.Session.Username = myUsername
    smtp1.Session.Password = myPassword

    'Send message
    smtp1.Send(message)

    'Logout gracefully
    smtp1.Close()
End Sub

Private Sub smtp1_Progress(ByVal sender As Object, ByVal e As SmtpProgressEventArgs) Handles smtp1.Progress
    'Update progress bar as message is sent
    progressBar1.Value = If(e.Final, 0, CInt((e.Position * 100) \ e.Length))
End Sub
Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         Dart.Mail.ComponentBase
            Dart.Mail.MailBase
               Dart.Mail.Smtp

See Also

Reference

Smtp Members
Dart.Mail Namespace


PowerTCP Mail for .NET Documentation Version 4.3
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic