PowerTCP Mail for .NET
Smtp Class
Members  Example  See Also  Send comments on this topic.
Dart.PowerTCP.Mail Namespace : Smtp Class




The Smtp component enables easy integration of Simple Mail Transport Protocol (SMTP) functionality within any .NET application.

Object Model

Smtp ClassCertificate ClassTcp ClassDeliveryStatusNotification ClassMailAddress ClassMailAddresses ClassMailAddress Class

Syntax

Visual Basic (Declaration) 
<LicenseProviderAttribute(SmtpLicenseProvider)>
Public Class Smtp 
   Inherits System.ComponentModel.Component
Visual Basic (Usage)Copy Code
Dim instance As Smtp
C# 
[LicenseProviderAttribute(SmtpLicenseProvider)]
public class Smtp : System.ComponentModel.Component 
Managed Extensions for C++ 
[LicenseProviderAttribute(SmtpLicenseProvider)]
public __gc class Smtp : public System.ComponentModel.Component 
C++/CLI 
[LicenseProviderAttribute(SmtpLicenseProvider)]
public ref class Smtp : public System.ComponentModel.Component 

Example

The following example demonstrates creating a basic MIME message with a single attachment.
Visual BasicCopy Code
' Be sure to import the namespace by putting "Imports Dart.PowerTCP.Mail"
' at the top of your class.

' Create a MessageStream object
Dim msg As New MessageStream()

' Add a normal recipient
msg.To.Add(New MailAddress("you@test.com"))

' Add a CC recipient
msg.CC.Add(New MailAddress("you2@test.com"))

' Add a BCC recipient
msg.BCC.Add(New MailAddress("you3@test.com"))

' Specify the sender
msg.From = New MailAddress("me@test.com")

' Specify the subject
msg.Subject = "Hello"

' Add some text to the message.
msg.Text = "Hi everyone. How are ya doing?"

' Add an attachment
msg.Attachments.Add("C:\files\graph.jpg")

' Specify the server
Smtp1.Server = "mail.test.com"

' Send the message
Smtp1.Send(msg)
C#Copy Code
// Be sure to import the namespace by putting "using Dart.PowerTCP.Mail;"
// at the top of your class.

// Create a MessageStream object
MessageStream msg = new MessageStream();

// Add a normal recipient
msg.To.Add(new MailAddress("you@test.com"));

// Add a CC recipient
msg.CC.Add(new MailAddress("you2@test.com"));

// Add a BCC recipient
msg.BCC.Add(new MailAddress("you3@test.com"));

// Specify the sender
msg.From = new MailAddress("me@test.com");

// Specify the subject
msg.Subject = "Hello";

// Add some text to the message.
msg.Text = "Hi everyone. How are ya doing?";

// Add an attachment
msg.Attachments.Add("C:\\files\\graph.jpg");

// Specify the server
smtp1.Server = "mail.test.com";

// Send the message
smtp1.Send(msg);

Remarks

The Smtp component enables the sending of Internet mail. The Smtp component is feature-rich and flexible, including many benefits not found in the .NET Platform's native SMTP support such as proxy support, Stream support, asynchronous use, access to the TCP connection, advanced debugging utilities, and more.

Using the Smtp Component

What follows are short descriptions of common usability issues. For a more complete, "walk-through" type description, see Using PowerTCP Secure Mail for .NET.

Automatic Session Management: Simply set the Smtp.Server property to the mail server you wish to use and call any method, such as the Smtp.Send method, to send a message. Login (and logout) will automatically occur, reducing any concern about managing sessions.

Synchronous Use: Most applications written with the Smtp component will be synchronous meaning that the application, when calling a synchronous method, will not execute the next line of code until the response is received. Use synchronous methods when sending mail does not have to be transparent to the user.

Asynchronous Use: The Smtp component fully supports asynchronous use, meaning that the application, when calling an asynchronous method, will immediately execute the next line of code without waiting for the response from the method. When the response is received, an event will be raised.

Sending Basic Mail Quickly: The Smtp.Send method is overloaded to provide an easy high-level way to send mail with only a single line of code.

Sending Advanced Mail: The Smtp.Send method is overloaded to allow the sending of a MessageStream object, allowing unprecedented ability to create email messages, no matter how complex the internal structure of the message needs to be!

Sending Commands: The Smtp.Connection.Send method can be used to send any command to an SMTP server, even custom commands.

Verifying email addresses: The Smtp component has built-in email verification support.

Displaying Progress: The Smtp.Progress event provides real-time notification of the number of bytes sent.

Viewing The SMTP Communication: The Smtp.Trace event enables access to all commands and data sent over the TCP connection.

Retrieving info about the control connection: The TCP control connection is exposed through the Smtp.Connection property, allowing access to low-level properties and methods. This can be used to view TCP-level activity, such as the local and remote IP address. The Tcp class can't be used on its own without a license for the PowerTCP Socket Objects.

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         Dart.PowerTCP.Mail.Smtp

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.