C # sending and receiving emails

Source: Internet
Author: User

Public void Sendmail (string input)
{
Strhost = "smtp.163.com"; // SMTP server address
Straccount = "itjy1127"; // SMTP service account
Strpwd = "yujie1127"; // SMTP service Password
Strfrom = "itjy1127@163.com"; // the sender's email address

Console. writeline (Sendmail ("497928062@qq.com", "QQ", input )? "Success": "unsuccess ");
Console. Readline ();
}

/** // <Summary>
/// Send an email
/// </Summary>
/// <Param name = "to"> recipient's email address </param>
/// <Param name = "title"> email title </param>
/// <Param name = "content"> body content </param>
/// <Returns> </returns>
Public bool Sendmail (string to, String title, string content)
{
Smtpclient _ smtpclient = new smtpclient ();
_ Smtpclient. deliverymethod = smtpdeliverymethod. Network; // specify the email sending Method
_ Smtpclient. Host = strhost; // specify the SMTP server
_ Smtpclient. Credentials = new system. net. networkcredential (straccount, strpwd); // user name and password

Mailmessage _ mailmessage = new mailmessage (strfrom, );
_ Mailmessage. Subject = title; // subject
_ Mailmessage. Body = content; // content
_ Mailmessage. bodyencoding = system. Text. encoding. utf8; // body Encoding
// _ Mailmessage. isbodyhtml = true; // set it to HTML Format
// _ Mailmessage. Priority = mailpriority. High; // priority

Try
{
_ Smtpclient. Send (_ mailmessage );
Return true;
}
Catch
{
Return false;
}
}

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.