protected void Button1_Click(object sender, EventArgs e)
{
try
{
SmtpClient sm = new SmtpClient();
MailMessage ms = new MailMessage();
ms.To.Add(new MailAddress(TextBox1 .Text ));
ms.Subject = TextBox2.Text;
ms.Body = TextBox3.Text;
ms.IsBodyHtml = true;
sm.Send(ms);
}
catch (Exception el)
{
Response.Write(el.Message);
}
}
问问题
4503 次
4 回答
1
SmtpClient 从 web.config 获取其配置,即 SMTP 服务器地址和身份验证字段(如果需要)。在 Send 行设置断点,检查 sm 对象的设置,确保 SMTP 参数正确,并且可以从测试此代码的任何位置访问服务器。
于 2012-10-04T03:11:41.867 回答
0
您需要设置连接设置(GMail 示例):
SmtpClient sm = new SmtpClient("smtp.gmail.com", 587);
sm.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "password");
sm.EnableSsl = true;
于 2012-10-04T03:13:20.657 回答
0
当您无法连接到 SMTP 服务器时会出现此问题,因此会出现超时消息。出现这个问题有几种可能:
- 错误的 SMTP 地址
- SMTP 被拒绝
- SMTP 服务器离线
- 端口设置
- SSL 配置
于 2012-10-04T03:34:57.253 回答
0
请在web.config
文件 中输入
<system.net>
<mailSettings>
<smtp from="yourEmailId@gmail.com">
<network host="smtp.gmail.com" port="587" userName="yourEmailId@gmail.com" password="***** " defaultCredentials="false"/>
</smtp>
</mailSettings>
</system.net>
于 2012-10-04T05:46:14.077 回答