First paste the code first
try { MailAddress receiver = new MailAddress ("zhan.com", "Mailbox"); MailAddress sender = new MailAddress (WebSettingsConfig.SenderAddress, "PC"); MailMessage message = new MailMessage (); message.From = sender; // Sender message.To.Add (receiver); // Recipient // message.CC.Add ( sender ); // CC sender message.Subject = model.Title; // Title message.Body = "Content : "+ Model.Content +" <br> Contact name: "+ model.SenderName +" <br> Contact email: "+ model.SenderEmail +" <br> Phone number: "+ model.SenderPhone; // Content message .IsBodyHtml = true;// Whether the supported content is HTML SmtpClient client = new SmtpClient ();// Whether the content is supported by HTML client.Host = "smtp.exmail.qq.com"; // client.Port = 587; client.EnableSsl = true; // Whether SSL is enabled //client.Timeout = 10000; // Timeout client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential (WebSettingsConfig .SenderAddress, WebSettingsConfig.SenderPassword); client.Send (message); return this.Json (new ResultU (true, ConstResult.success, "mail sent successfully!")); } Catch (Exception ex) { LogFile.WriteErrorLog (DateTime.Now + "mail sending failed:" + ex.Message); return this.Json (new ResultU (false, ConstResult.fail, "Failed to send email!")); }
There is nothing special about the code for sending emails, but because of the failure of sending with Tencent's corporate email, it always prompts for timeout. There are also some solutions found online, almost all do not use SSL, use port 25. Not feeling good
Look at Tencent's official setup instructions, using SSL, port number 465, but if you press the configuration, it always prompts timeout. No way, googled and found that the port number should be 587
You can check it out here https://stackoverflow.com/questions/15796530/what-is-the-difference-between-ports-465-and-587
So in fact it is not misleading by Tencent, it can only be said that it is lack of knowledge