Send mail with C # support implicit SSL

Source: Internet
Author: User
Tags call back mailmessage

Install the package:

Install-package AIM

Use the following code to send:

Class mail{private static string mailaddress = "{You email address}";    private static string host = "{Your host server}";    private static string UserName = "{Your user name}";    private static string Password = "{Your password}";    private static string Userto = "{to address}";  private static void SendEmail (string subject, String message) {//generate message var mailmessage = new        Mimemailmessage ();        Mailmessage.from = new Mimemailaddress (mailaddress);        MAILMESSAGE.TO.ADD (Userto);        Mailmessage.subject = Subject;        mailmessage.body = message;        Create SMTP Client var mailer = new Mimemailer (host, 465); Mailer.        User = UserName; Mailer.        Password = Password; Mailer.        Ssltype = Sslmode.ssl; Mailer.        Authenticationmode = authenticationtype.base64; Set a delegate function for call back mailer.        sendcompleted + = compevent; Mailer.    Sendmailasync (MailMessage); }//call back Function private static void Compevent (object sender, AsyncCompletedEventArgs e) {if (e.userstate! = null)        Console.Out.WriteLine (E.userstate.tostring ());        Console.Out.WriteLine ("Is it canceled?" + e.cancelled);    if (e.error! = null) Console.Out.WriteLine ("Error:" + e.error.message); }}

  

Send mail with C # support implicit SSL

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.