asp.net 发送邮件

发布于 2024-08-04 07:57:27 字数 559 浏览 3 评论 0原文

我正在编写一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吃素的狼 2024-08-11 07:57:27

您需要添加要使用的 SMTP 服务器,例如

System.Web.Mail.SmtpMail.SmtpServer = "mail.provider.com";

也许您可能想看看 System.Net.Mail,这是 .Net 2 中的新邮件类,System.Web.Mail 是已过时。

You need to add the SMTP server you want to use, something like

System.Web.Mail.SmtpMail.SmtpServer = "mail.provider.com";

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.

梨涡少年 2024-08-11 07:57:27

通常,此异常必须处理以下代码行(或者我应该说缺少以下代码行):

SmtpMail.SmtpServer = "mail.your-domain.com"

默认情况下,如果未设置 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):

SmtpMail.SmtpServer = "mail.your-domain.com"

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

玉环 2024-08-11 07:57:27

另一条评论:我发现在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文