我收到了錯誤「服務器不支持安全連接」與我的代碼如下。服務器不支持在C#中的安全連接
SmtpClient smtp = new SmtpClient();
MailMessage mail = new MailMessage();
mail.From = new MailAddress("*****@gmail.com");
mail.To.Add(recieverId);
mail.Subject = "Invoice Copy and Delivery Confirmation for booksap.com Order " + orderno + ". Please Share Feedback.";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(Server.MapPath("OrderMail\\Invoice.pdf"));
mail.Attachments.Add(attachment);
MailBody = "We are pleased to inform that the following items in your order " + orderno + " have been placed. This completes your order. Thank you for shopping! ";
StreamReader reader = new StreamReader(Server.MapPath("~/MailHTMLPage.htm"));
string readFile = reader.ReadToEnd();
string myString = "";
myString = readFile;
myString = myString.Replace("$$Name$$", ContactPersonName);
myString = myString.Replace("$$MailBody$$", MailBody);
mail.Body = myString.ToString();
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = true;
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("*******@gmail.com", "*******");
smtp.Send(mail);
mail.Dispose();
mail = null;
我該如何解決這個問題? 如果我設置
EnabledSsl = false
它會返回錯誤:SMTP服務器要求安全連接或客戶端未通過身份驗證。服務器響應是:5.7.1客戶端未通過身份驗證。
我認爲Gmail的SMTP是不工作的少安全連接。剛剛嘗試過sendgrid或搜索其他電子郵件服務 –
好吧,先生,我會盡力回覆給你。 – Abhishek