Csharp: Send Email

Source: Internet
Author: User
Tags mailmessage smtpclient

/// <Summary> /// producer /// aggregation /// 20130816 /// </summary> /// <param name = "to"> recipient </param> /// <param name = "toName"> recipient name </param> /// <param name = "subject"> subject name </param> /// <param name = "body"> content </param> /// <returns> </returns> public bool SendMailMessage (string, string toName, string subject, string body) {bool re = false; try {int id = 1; string bcc = "463588883@qq.com"; string bccName = "geovi Ndu "; string cc = string. empty; string ccDisName = string. empty; vipSetMailHostInfo = vipSetMailHostBLL. selectVipSetMailHost (id); // Instantiate a new instance of MailMessage mMailMessage = new MailMessage (); // Set the sender address of the mail message mMailMessage. from = new MailAddress (vipSetMailHostInfo. smtpUser, vipSetMailHostInfo. smtpName); // Set the specified ient address of the ma Il message mMailMessage. to. add (new MailAddress (to, toName); // indicates the email address, and sends the email address, it can be a collection list // Check if the bcc value is null or an empty string if (bcc! = Null) & (bcc! = String. empty) {// Set the Bcc address of the mail message mMailMessage. bcc. add (new MailAddress (bcc, bccName); // bcc} // Check if the cc value is null or an empty value if (cc! = Null) & (cc! = String. empty) {// Set the CC address of the mail message mMailMessage. CC. add (new MailAddress (cc, ccDisName); // copy the email} // Set the subject of the mail message mMailMessage. replyTo = new MailAddress ("vip@dupcit.com", "VIP guest"); // returns the Response Message success // mMailMessage. replyTo = "VIP"; mMailMessage. subject = subject; // Set the body of the mail message mMailMessage. body = body; // Set the format of the mail message body as HTML mMailMessage. isBodyHtml = true; mMailMessage. bodyEncoding = System. text. encoding. UTF8; // Set the priority of the mail message to normal mMailMessage. priority = MailPriority. normal; // Instantiate a new instance of SmtpClient // SmtpClient mSmtpClient = new SmtpClient (); SmtpClient SmtpServer = new SmtpClient (vipSetMailHostInfo. smtpServer); SmtpServer. credentials = new NetworkCredential (vipSetMailHostInfo. smtpUser, vipSetMailHostInfo. smtpPasswor); SmtpServer. port = 25; SmtpServer. enableSsl = false; // Send the mail message SmtpServer. send (mMailMessage); re = true;} catch (Exception ex) {ex. message. toString (); re = false;} return re ;}

 

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.