asp.net 发送邮件
我正在编写一个使用 asp.net 发送邮件的程序,它给我一个错误,因为“SendUsing”配置值无效。这是我的代码
protected void Button2_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.To = "[email protected]";
msg.From = "[email protected]";
msg.Subject = "hello";
SmtpMail.Send(msg);
}
i am writing a program to send mail using asp.net, it gives me an error as the "SendUsing" configuration value is invalid. Here is my code
protected void Button2_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.To = "[email protected]";
msg.From = "[email protected]";
msg.Subject = "hello";
SmtpMail.Send(msg);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要添加要使用的 SMTP 服务器,例如
也许您可能想看看 System.Net.Mail,这是 .Net 2 中的新邮件类,System.Web.Mail 是已过时。
You need to add the SMTP server you want to use, something like
Perhaps you might want to take a look at the System.Net.Mail, which is the new mail class in .Net 2, System.Web.Mail is obsolete.
通常,此异常必须处理以下代码行(或者我应该说缺少以下代码行):
默认情况下,如果未设置 SmtpMail.SmtpServer,则 System.Web.Mail 应该使用 localhost 作为默认值财产。然而,由于某种原因,这似乎不起作用。
您可以对此进行简单的谷歌搜索;-)
来源
Typically this exception has to deal with the following line of code (or I should say ABSENCE of the following line of code):
By default, if SmtpMail.SmtpServer is not set, System.Web.Mail is supposed to use localhost as the default property. However, for some reason this doesn't appear work.
You could have done a simple google search for this ;-)
Source
另一条评论:我发现在 Server 2008 上,您的网站需要在具有除 ApplicationPoolIdentity(默认)之外的标识的应用程序池中运行,以便通过 localhost 发送电子邮件(即,未设置 SmtpMail.SmtpServer)。所有其他身份都有效(NetworkService、LocalService、LocalSystem),只是 ApplicationPoolIdentity 无效。
如果将 SmtpMail.SmtpServer 指定为 null 或 localhost 以外的其他值,则可以使用 ApplicationPoolIdentity。
One additional comment: I found that on Server 2008, your website needs to run in an application pool with identity other than ApplicationPoolIdentity (the default) for e-mail to be sent via localhost (i.e., no SmtpMail.SmtpServer set). All of the other identities work (NetworkService, LocalService, LocalSystem), just not ApplicationPoolIdentity.
If you specify SmtpMail.SmtpServer as something other than null or localhost, ApplicationPoolIdentity can be used.