. NET MVC Mail Delivery

Source: Internet
Author: User
Tags mailmessage smtpclient

In previous projects, the Web site was designed to send mail, and a piece of code was looked up on the internet for a moment:

 private static void SendEmail (String clienthost, String EmailAddress, String re  Ceiveaddress, String userName, string password, string subject, String body) {MailMessage mail            = new MailMessage (); Mail.            from = new MailAddress (emailaddress); Mail.            To.add (New MailAddress (receiveaddress)); Mail.            Subject = Subject; Mail.            BODY = body; Mail.            Isbodyhtml = true; Mail.            Deliverynotificationoptions = deliverynotificationoptions.onfailure;            SmtpClient client = new SmtpClient (); Client.            Host = ClientHost; Client.            Credentials = new NetworkCredential (userName, password); Client.            Deliverymethod = Smtpdeliverymethod.network; try {client.            SendAsync (Mail,null); } catch (Exception) {}} 

In the local test no problem, but the deployment to the window server2012 can not send, and then on the internet Baidu a bunch, configure the mail server is not satisfactory, and later found a deprecated code is normal:

  public static void SendEmail (string from, string subject, String body, list<string> mailaddress, string host, int            Port, string password) {System.Web.Mail.MailMessage Mail = new System.Web.Mail.MailMessage (); try {mail. to = string.                Join (",", mailaddress); Mail.                from = from; Mail.                Subject = Subject; Mail.                BodyFormat = System.Web.Mail.MailFormat.Html; Mail.                BODY = body; Mail. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); Authentication mail. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/sendusername", mail. from); Email login, here is the same as the previous send account mail. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/sendpassword", password); This password to note: If it is a general account, to use the authorization code, Enterprise account with login password mail. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);//Port Mail. FielDs. ADD ("Http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");//ssl encryption System.web.mail.smtpmail.s    Mtpserver = "smtp.qq.com";                Enterprise account with smtp.exmail.qq.com System.Web.Mail.SmtpMail.Send (Mail); Message sent successfully} catch (Exception ex) {//failure, error message: Ex.            Message; }        }

  

Later discovered may be because the server is set up in the intranet, the specific port is not open or some restrictions, but because of the work requirements, temporarily can only step backward, must be corrected later.

. NET MVC Mail Delivery

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.