8.2. Design
It is relatively easy to create an e-mail message and send it to a recipient using the .NET Framework. The following few lines of code will accomplish that:
//Add the following using directive to the beginning of the file //using System.Net.Mail; SmtpClient client = new SmtpClient("127.00.00.1"); MailMessage mail = new MailMessage(new MailAddress("from@PoweredByV2.com"), new MailAddress("to@hotmail.com")); mail.Subject = "test"; mail.Body = "test"; client.Send(mail);
8.2.1. SmtpClient Class
The SmtpClient class represents the object that handles sending a message. When you create the SmtpClient object, you set the SMTP server's address so the system knows where to relay the message. You can also pass in a port number to the constructor if needed or set the Port property after the object is created. The following table provides a short description of all the properties for the SmtpClient class.
Property | Description |
---|---|
ClientCertificates | Specifies which certificates should be used to establish the Secure Sockets Layer (SSL) connection |
Credentials | Gets or sets the credentials used to authenticate the sender |
DeliveryMethod | Specifies how outgoing e-mail messages will be handled |
EnableSsl | Specifies whether the SmtpClient uses Secure Sockets Layer (SSL) to encrypt the connection |
Host | Gets or sets the name or IP address of the host used for SMTP transactions |
PickupDirectoryLocation | Gets or sets the folder where applications save e-mail messages to be processed by the local SMTP server |
Port ... |
Get ASP.NET 3.5 Enterprise Application Development with Visual Studio® 2008: Problem - Design - Solution now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.