我已創建了一個mail.aspx.cs與下面的代碼在client.send(消息)上發送郵件時出錯?
protected void Page_Load(object sender, EventArgs e)
{
MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress("[email protected]"));
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient();
client.Send(message);
}
而且web.config設置
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtpserver1" port="25" userName="abc xyz" password="abc" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
獲取失敗錯誤,而在下面的行
client.Send(message); mail sending fail,
在頁面加載發送郵件
我是新來的asp.net,指導我解決這個問題的正確方法。
當你發佈任何問題。不要發佈您的原始用戶名密碼,任何機構都可能會濫用它。請用虛擬用戶名和密碼替換它。 – Raghubar
不是解決方案,但是您應該使用'使用(MailMessage消息=新MailMessage()){...使用(SmtpClient客戶端=新SmtpClient()){...}}' –