Sharing makes people happy. The pits encountered are shared to you through blog posts, and solutions are summarized to save more people valuable time to do other things, so I decided to write this blog post;
Alibaba cloud failed to send SMTP mail. Alibaba cloud server can't send email. The third method is to use port 25 instead of port 465. Alibaba cloud has succeeded in sending email. Now Alibaba cloud's port 25 management is very strict, and it's too difficult to apply. I've applied for success or failure, and I've applied for failure recently. I'll use the third method to configure port 465 directly
The first method:
The company recently installed an Alibaba cloud server. After I deployed the system, I found that I couldn't send email. Ah, how could I not send email? So we found out that Alibaba cloud server disabled the default 25 port of e-mail in order to prevent e-mail flooding,
OK, so I thought about how to unseal port 25. I looked for the official information and understood it, but I didn't find the corresponding menu. The unsealing function of port 25 was hidden too deeply and took a lot of time. Finally, I found it. The last figure shows how to click the unsealing function of port 25 in the menu. The following are the steps of unsealing:
Step 1: move the mouse over your Alibaba cloud account [Nanjing XXXX] in the upper right corner, which is the first one on the left of the [simplified Chinese] function;
Step 2: click [security control];
Step 3: click [25 port unsealing]
Step 4: click [25 port unsealing application]
Step 5: fill in the applied IP and the corresponding email domain name. Note that the IP address of the server must be the server under the Alibaba cloud account. If the domain name is different, different suppliers have different domain names. Customers buy Alibaba cloud email, and the email domain name is mail zhsiwei. Com configuration is successful, QQ email can fill in mail qq. You can use the qq.com domain name to send the email qq. Com configuration application is not successful. Mailbox 126 and Yahoo mailbox are not listed one by one here. You can go to the corresponding mailbox to find it. Remember that this mailbox domain name is very important. If the configuration is not good, it will fail to pass the audit.
Step 6: fill in the application form
Step 7: after filling in and confirming, wait quietly for Alibaba cloud customer service review. Generally, it takes up to 7 working days
The second method:
Method source: https://blog.csdn.net/u013571196/article/details/78376343
Thinking that Alibaba cloud likes to use security groups to shield ports, I quickly configured security rules. The inbound and outbound are configured, but it still doesn't work. Then simply turn off the firewall, but it still doesn't work. After some tossing, it was found that Ali had its own shielded port 25. It was embarrassing. Later, I found some rules documents from Ali and found that I needed to apply for opening a shielded port. However, after consulting Alibaba staff, it is found that port 25 is not open now, because the measures for the administration of Internet information services and the anti spam specification of Internet association of China all specify and manage spam. Let me consider SSL encryption and SMTP sending through port 465. Then I tried a wave and found that 465 couldn't send QQ email. I tried port 587 and succeeded.
System. Net. The code of mail space is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 public static bool SendTheMail(string strto, string subj, string bodys) { SmtpClient _smtpClient = new SmtpClient(); _smtpClient.EnableSsl = true; _smtpClient.UseDefaultCredentials = false; _smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; _smtpClient.Host = "smtp.qq.com"; _smtpClient.Port = 587; _smtpClient.Credentials = new System.Net.NetworkCredential("aaa@qq.com", "666"); //The password is not a QQ password, but a key generated by the POP3/SMTP service in the QQ account settings MailMessage _mailMessage = new MailMessage("aaa@qq.com", "888@yeah.net"); _mailMessage.Subject = subj;//Theme _mailMessage.Body = bodys;//content _mailMessage.BodyEncoding = Encoding.Default;//Text coding _mailMessage.IsBodyHtml = true;//Format as HTML _mailMessage.Priority = MailPriority.High;//Priority try { _smtpClient.Send(_mailMessage); Console.WriteLine("Sent successfully"); return true; } catch (Exception e) { Console.WriteLine("fail in send"); throw e; } }
The third method:
This method is officially given, mainly through system Web. Mail. Mailmessage to realize sending. Just put this method into your own project and call it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 /// <summary> ///Through system Web. Mail. Mailmessages can be sent without Alibaba cloud's restriction on the use of port 25 ///Port 465 is generally used for the time being /// </summary> ///< param name = "SMTP server" > SMTP service, for example: SMTP 126.com</param> ///< param name = "username" > outbox < / param > ///< param name = "PWD" > password < / param > ///< param name = "nickname" > nickname < / param > ///< param name = "strfrom" > outbox < / param > ///< param name = "strto" > inbox < / param > ///< param name = "messagesubject" > subject < / param > ///< param name = "MessageBody" > content < / param > ///< param name = "supfile" > attachment < / param > ///< param name = "port" > port < / param > ///< param name = "enablessl" > SSL encryption < / param > /// <returns></returns> public static bool SendWebEmail(string smtpserver, string userName, string pwd, string nickName, string strfrom, string strto, string MessageSubject, string MessageBody, string SUpFile, int port, int enablessl = 0) { System.Web.Mail.MailMessage mmsg = new System.Web.Mail.MailMessage(); //Mail subject mmsg.Subject = MessageSubject; mmsg.BodyFormat = System.Web.Mail.MailFormat.Html; //Message body mmsg.Body = MessageBody; //Text coding mmsg.BodyEncoding = Encoding.UTF8; //priority mmsg.Priority = System.Web.Mail.MailPriority.High; System.Web.Mail.MailAttachment data = null; if (SUpFile != "") { SUpFile = HttpContext.Current.Server.MapPath(SUpFile);//Get attachment at local address System.Web.Mail.MailAttachment attachment = new System.Web.Mail.MailAttachment(SUpFile); //create the attachment mmsg.Attachments.Add(attachment); //add the attachment } //Sender email address mmsg.From = string.Format("\"{0}\"<{1}>",nickName, strfrom); //Recipient receiving address mmsg.To = strto; mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //user name mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName); //The password is not the mailbox login password, but the third-party client authorization code generated when setting POP3/SMTP in the mailbox mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", pwd); //port mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", port); //Use SSL mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", (enablessl == 1 ? "true" : "false")); //Smtp server System.Web.Mail.SmtpMail.SmtpServer = smtpserver; try { System.Web.Mail.SmtpMail.Send(mmsg); } catch (Exception ex) { LogHelper.Error(ex.ToString()); return false; } return true; }
Alibaba cloud failed to send SMTP mail. Alibaba cloud server cannot send mail. Note that the password filled in is not the mailbox login password {but the authorization code of the third-party client generated when setting POP3/SMTP in the mailbox,
Original text: https://www.cnblogs.com/axinno1/p/8303130.html