2016-05-14 75 views
0

的eror发送电子邮件:从我的网站

System.Net.Mail.SmtpException:SMTP服务器要求安全连接 或客户端未通过身份验证。服务器响应 是:5.5.1需要身份验证。在System.Net.Mail.MailCommand.Send(SmtpConnection 康恩,字节[]命令,从MailAddress,布尔allowUnicode)在 详细处 System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode的StatusCode, 字符串响应) System.Net.Mail.SmtpTransport.SendMail(MailAddress发件人, MailAddressCollection收件人,字符串deliveryNotify,布尔 allowUnicode,SmtpFailedRecipientException &除外)处 forgot.Button1_Click System.Net.Mail.SmtpClient.Send(消息MAILMESSAGE)(对象发件人,EventArgs e) c:\ Users \ Champion \ Desktop \ DinoSite \ forgot.aspx.cs:line 24

的C#

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Net.Mail; 

public partial class forgot : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      using (var client = new SmtpClient()) 
      { 
       MailMessage mail = new MailMessage("[email protected]", (string)Email.Text); 
       mail.Subject = "this is a test email."; 
       mail.Body = "this is my test email body"; 
       client.Send(mail); 
      } 
      lblError.Text = "Message sent!"; 
     } 
     catch (Exception ex) 
     { 
      lblError.Text = ex.ToString(); 
     } 
    } 
} 

在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="[email protected]"> 
       <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> 
+0

尝试Gmail – NineBerry

+0

其他不同的供应商,我试图和zhcon失败 –

+0

如果它的工作原理更改端口为465(smtps)? –

回答

0

→使用SMTP安全端口:465

→强制你的脚本,使SMTP验证:

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