的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>
嘗試Gmail – NineBerry
其他不同的供應商,我試圖和zhcon失敗 –
如果它的工作原理更改端口爲465(smtps)? –