C # mail sending method [NetMail mode]

Source: Internet
Author: User
Tags mailmessage smtpclient

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
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.