【发布时间】:2016-01-11 04:35:08
【问题描述】:
任何人都可以在这里提供帮助:我有这个 asp.net 表单正在尝试作为电子邮件发送,这里是代码:
try
{
MailMessage mailSend = new MailMessage();
mailSend.From = new MailAddress("williams@iquo.com.ng");
mailSend.To.Add("williams@iquo.com.ng");
mailSend.Subject = "Contact message from www.iquo.com.ng";
mailSend.Body = "<b>My name is: </b>" + firstName.Text + lastName.Text + "<br/>" + "<b>My phone number is: </b>" + pNumber.Text + "<br/>"
+ "<b>My email address is: </b>" + email.Text + "<br/>" + "<b>The message is: </b>" + message.Text;
mailSend.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient("smtp.iquo.com.ng", 25);
smtpClient.Credentials = new System.Net.NetworkCredential("williams@iquo.com.ng", "password");
smtpClient.Send(mailSend);
firstName.Enabled = false;
lastName.Enabled = false;
pNumber.Enabled = false;
email.Enabled = false;
message.Enabled = false;
Response.Redirect("about-me.html");
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
有什么问题吗?为什么邮件发不出去?另外,我把这个:
<system.net>
<mailSettings>
<smtp>
<network host="smtp.iquo.com.ng" userName="williams@iquo.com.ng" password="password />
</smtp>
</mailSettings>
</system.net>
按照服务器管理员的指示进入 web.config 文件。我能做什么?
【问题讨论】:
-
您的 SMTP 服务器工作正常吗?您应该先使用 gmail、hotmail 等公共 SMTP 服务器来测试您的代码,然后再使用您的服务器重试。
-
是否出现异常?你检查过吗?还要检查你的 smtp 配置。
-
如果您在企业防火墙内工作,请检查端口 25 是否打开
-
如果您在代理后面运行代码,您应该将代理添加到
内的 web.config 中。详情见这里stackoverflow.com/questions/3311746/… -
您的密码中缺少引号。
password="password />