Send mail using SMTP

Source: Internet
Author: User
Tags mailmessage smtpclient

Define a mail entity first:

 Public classEntitymail {/// <summary>        ///Sender/// </summary>         Public stringfrom {Get;Set; } /// <summary>        ///Recipient/// </summary>         Public stringto {Get;Set; } /// <summary>        ///         /// </summary>         Public stringCc {Get;Set; } /// <summary>        ///         /// </summary>         Public stringBCC {Get;Set; } /// <summary>        ///title/// </summary>         Public stringSubject {Get;Set; } /// <summary>        ///content/// </summary>         Public stringBody {Get;Set; } /// <summary>        ///Accessories/// </summary>         Public stringAttachments {Get;Set; } /// <summary>        ///         /// </summary>         Public intRetrytime {Get;Set; } /// <summary>        ///         /// </summary>         Public stringimportance {Get;Set; } /// <summary>        ///Password/// </summary>         Public stringPassword {Get;Set; } }
View Code
/// <summary>        ///Send mail/// </summary>        /// <param name= "Mail" >Mail</param>         Public Static voidsendbysmtp (Entitymail mail) {varSMTPHost = configurationmanager.appsettings["Smtpserverhost"]; if(SMTPHost = =NULL)            {                Throw NewSystem.Exception ("Smtpserverhost is not configured in appsettings. "); }            intPort =0; if(!int. TryParse (Common.getappsetting ("Smtpserverport"), outport)) {Port= -; }            //Host: Mail server, port: PortsSmtpClient SmtpClient =NewSmtpClient (SMTPHost, Port); //whether to enable Secure Sockets Layer encrypted connectionsSmtpclient.enablessl =false;//Mail ObjectMailMessage MailMessage =Newmailmessage (mail. From, Mail. To, Mail. Subject, Mail.            Body); //Message PriorityMailmessage.priority =Mailpriority.normal; //Sender AuthenticationSmtpclient.credentials =Newnetworkcredential (mail. From, Mail.            Password); //Start Sendingsmtpclient.send (mailmessage);}

Send mail using SMTP

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.