February 2009
Intermediate to advanced
502 pages
12h 53m
English
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);
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 ... |
Read now
Unlock full access