Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从我的网站发送电子邮件_C#_Email - Fatal编程技术网

C# 从我的网站发送电子邮件

C# 从我的网站发送电子邮件,c#,email,C#,Email,eror: System.Net.Mail.SmtpException:SMTP服务器需要安全的 连接或客户端未通过身份验证。服务器响应 was:5.5.1需要身份验证。了解更多信息,请访问 System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode状态码, 字符串响应)在System.Net.Mail.MailCommand.Send(SmtpConnection)中 conn,Byte[]命令,MailAddress from,布尔all

eror:

System.Net.Mail.SmtpException:SMTP服务器需要安全的 连接或客户端未通过身份验证。服务器响应 was:5.5.1需要身份验证。了解更多信息,请访问 System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode状态码, 字符串响应)在System.Net.Mail.MailCommand.Send(SmtpConnection)中 conn,Byte[]命令,MailAddress from,布尔allowUnicode)位于 System.Net.Mail.SmtpTransport.SendMail(邮寄地址发送者, MailAddressCollection收件人,字符串deliveryNotify,布尔值 allowUnicode、SmtpFailedRecipientException和exception)在 System.Net.Mail.SmtpClient.Send(MailMessage)位于 忘记。按钮1\u在中单击(对象发送者、事件参数) c:\Users\Champion\Desktop\DinoSite\forget.aspx.cs:24行

c#

在Web配置中:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5.2" />
  </system.web>
  <system.net>
    <mailSettings>
        <smtp deliveryMethod="Network" from="ozcohen06@gmail.com">
                <network host="smtp.gmail.com" userName="ozcohen06" password="mypass" port="587" enableSsl="true" />
        </smtp>
    </mailSettings>
</system.net>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  </system.serviceModel>
</configuration>

需要考虑的要点:

1) 对不太安全的应用程序的访问已“打开”


2) 为您的google帐户启用从其他时区/IP登录→ 使用SMTP安全端口:465

→ 强制脚本进行SMTP身份验证:

mail.UseDefaultCredentials = false;
mail.Credentials = basicCredential;

尝试Gmail以外的其他提供程序如果将端口更改为465(smtps)是否有效?添加:smtp.UseDefaultCredentials=false;大多数公司网络将阻止465这样的端口。关闭网络凭据将连接到邮件服务器,而不在本地网络上使用smtp。您正在连接到基于web的gmail帐户。仅当您在网络上有outlook帐户,该帐户使用代理服务器连接到outlook服务器时,才需要网络凭据。使用代理服务器,端口转发用于通过阻止端口465的防火墙。Net 3.5默认为关闭凭据,Net 4.0默认为msdn所说的安全修复程序。在哪里添加此项?
mail.UseDefaultCredentials = false;
mail.Credentials = basicCredential;