我只是在测试从本地主机发送到 gmail.com 的电子邮件
***Webconfig:***
<system.net>
<mailSettings>
<smtp>
<network
host="localhost"
port="25"
/>
</smtp>
</mailSettings>
</system.net>
***Default.aspx:***
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MasterApps._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
***Code behind is:***
protected void Button1_Click(object sender, EventArgs e)
{
MailAddress from = new MailAddress("mwaghela7@gmail.com");
MailAddress to = new MailAddress("mwaghela7@gmail.com");
MailMessage msg = new MailMessage(from, to);
msg.Subject = "hi";
msg.Body = "hello";
SmtpClient sc = new SmtpClient();
sc.Send(msg);
}
它的触发错误如下:
* System.dll 中出现“System.Net.Mail.smtp failedReceipientExeception”类型的异常,但未在用户代码中处理。附加信息:邮箱不可用。服务器响应为:5.7.1。无法中继 mwaghela7@gmail.com
上面的代码有什么问题?如何解决这个问题?