服务器不支持安全连接在C# [英] Server does not support secure connections in C#

查看:488
本文介绍了服务器不支持安全连接在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的代码中收到错误服务器不支持安全连接。

  SmtpClient smtp = new SmtpClient(); 
MailMessage mail = new MailMessage();
mail.From = new MailAddress(***** @ gmail.com);
mail.To.Add(recieverId);
mail.Subject =booksap.com订单的发票复印和交货确认+ orderno +。请分享反馈。
System.Net.Mail.Attachment附件;
attachment = new System.Net.Mail.Attachment(Server.MapPath(OrderMail\\Invoice.pdf));
mail.Attachments.Add(attachment);
MailBody =我们很高兴地通知您,您的订单中的以下项目+ orderno +已被放置。这完成了您的订单。
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客户端未通过身份验证。

解决方案

@Abhishek是您的代码已写入将发送消息到服务器只是检查您的邮箱(***@gmail.com),但smtp客户端的谷歌是阻止你进入他们的域。
您必须使您的Gmail不太安全,您需要允许登录尝试。



我认为它关于验证码和机器人,防止这种登录,知道的人可以抛出一些光这些东西。使您的帐户更少可疑。希望这有助于


I'm getting the error "Server does not support secure connections" with my code below.

            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;

How can I fix this issue? If I set

 EnabledSsl = false

it will return the error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated.

解决方案

@Abhishek Yes.The code that you have written will send the message to the server just check your mail box (***@gmail.com) but smtp client of google is preventing you from entering into thier domain. You have to make your gmail less secure that is you need to allow sign in attempt.

Check Your mail box,you should have such response from gmail domain and you need to make your account less secure.

I think its about captcha and bots preventing such logging in,people who know can throw some light in these things.Make your account less suspicious.Hope this helps

这篇关于服务器不支持安全连接在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆