Class for sending e-mail. It can be sent (recommended) after testing)

Source: Internet
Author: User
Tags mailmessage smtpclient

Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. Collections. Generic;
Using system. net. mail;
Using system. net;
Using system. IO;

Namespace kuaican. Web
{
/// <Summary>
/// Class for sending e-mail. It can be sent (recommended) after testing)
/// </Summary>
Public class sendmail
{
Public String sendemail (string toaddr, String title, string content)
{
Mailmessage MSG = new mailmessage ();
MSG. to. Add (toaddr );
MSG. to. Add ("xxxxxxxxxx@163.com ");
MSG. CC. Add ("xxxxxxxxxx@163.com ");
MSG. From = new mailaddress ("xxxxxxxxxx@163.com", "automation Mercer", system. Text. encoding. utf8 );
MSG. Subject = title;
MSG. subjectencoding = system. Text. encoding. utf8;
MSG. Body = content;
MSG. bodyencoding = system. Text. encoding. utf8;
MSG. isbodyhtml = false;
MSG. Priority = mailpriority. normal;
Smtpclient client = new smtpclient ();
Client. Credentials = new networkcredential ("xxxxxxxxxx@163.com", "password ");
Client. Port = 25; // 587,465,995
Client. Host = "smtp.163.com ";
// Client. enablessl = true;
// Object userstate = MSG;
Try
{
Client. Send (MSG );
Return "sucess ";
}
Catch (smtpexception ex)
{
Return ex. Message + "sendemail error ";
}
}

}
}

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.