In the previous Blog Post C # mail sending method [webMail method], we introduced the mail sending method of Webmail. Now we will introduce how to use NetMail to send mail in C,
The test code is as follows:
/// <Summary>
/// NetMail passed the test
/// </Summary>
Private void TestSend ()
{
System. Net. Mail. MailMessage mm = new System. Net. Mail. MailMessage ();
// Recipient address
Mm. To. Add (new System. Net. Mail. MailAddress ("xxxxxx@163.com", "Name "));
// Sender address
Mm. From = new System. Net. Mail. MailAddress ("xxxxx@sina.com ");
// This parameter can be left unspecified.
// Mm. Sender = new System. Net. Mail. MailAddress ("xxx@sina.com", "SenderName ");,
Mm. Subject = "This is Test Email ";
Mm. Body = "Mm. IsBodyHtml = true;
Mm. Priority = System. Net. Mail. MailPriority. High; // you can specify the Mail Priority.
System. Net. Mail. SmtpClient smtCliend = new System. Net. Mail. SmtpClient ();
// Specify the email server
SmtCliend. Host = "smtp.sina.com ";
// Smtp mail server port number
SmtCliend. Port = 25;
// Set the user name and address of the sender's email address, which must be provided by the public mail server. Otherwise, the email will not be sent successfully.
SmtCliend. Credentials = new NetworkCredential ("xxxxxxx", "xxxxxxx ");
// Specify the mail sending Method
SmtCliend. DeliveryMethod = System. Net. Mail. SmtpDeliveryMethod. Network;
Try
{
SmtCliend. Send (mm );
}
Catch (System. Net. Mail. SmtpException ex)
{
Response. Write (ex. Message );
}
Catch (Exception ex)
{
Response. Write (ex. Message );
}
}
From weizhiai12's column