【问题标题】:How I can send a html mail in ASP.NET with C#?如何使用 C# 在 ASP.NET 中发送 html 邮件?
【发布时间】:2012-11-23 01:50:13
【问题描述】:

我有一个 ASP.NET 应用程序,可以将数据添加到数据库并从该数据库中获取数据。此应用程序用于创建与我们网络的访客连接。如果将用户添加到数据库并且 Radius 服务器允许用户收到包含其登录数据的电子邮件。用户名和密码。我想做一个html邮件。但我不知道如何在 ASP.NET 中做到这一点,所以我阅读了一些关于它的教程,我发现了这段代码:

http://www.codeproject.com/Articles/12182/ASP-NET-Sending-mail-using-SMTP-in-HTML-format-us

这是我的代码:

 MailMessage mail = new MailMessage();
                mail.To = "<here is my company email>";
                mail.From = "test@domain.de";
                mail.BodyFormat = MailFormat.Html;
                mail.Subject = "testheader";
                mail.Body =
                    "<html><body><Table><tr><td>Hi,</td></tr><tr><td>Details of the Statistics :</td></tr></Table></body></html><html><body>" +
                    "sometext" +
                    "</body></html><html><body><Table><tr><td> </td></tr><tr><td>NOTE: This is an automated mail. Please, do not reply.</td></tr>" +
                    "<tr><td>*Green coloured rows indicates temporary demos</td></tr>" +
                    "<tr><td>**All statistics are based on the page naming conventions Eg., 22_10_2005_</td></tr>" +
                    "<tr><td> </td></tr><tr><td>Regards,</td></tr><tr><td>some text,</td></tr><tr><td>some text,</td></tr>" +
                    "<tr><td> Some text </td></tr></table></body></html>";

                SmtpMail.SmtpServer = "<smtp ip>";
                SmtpMail.Send(mail);

我尝试这个并得到错误:

The server rejected the sender address. The server response was: 530 5.7.1 Client not authenticated 

IP 是正确的,但我必须为经过身份验证的用户做些什么……我该怎么做?

【问题讨论】:

标签: c# asp.net html email smtp


【解决方案1】:

您必须在您的Web.config 文件中配置SMTP server mailSettings

  <system.net >
    <mailSettings>
      <smtp deliveryMethod="Network" from="someaddress@classifiedspak.com">
        <network
        host="mail.classifiedspak.com"
        userName="someaddress@classifiedspak.com "
        password="*************"
        port="25" />
      </smtp>
    </mailSettings>
  </system.net>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-01
    • 2013-08-22
    • 1970-01-01
    • 2013-02-22
    • 2014-08-14
    • 2012-03-28
    • 2011-11-21
    相关资源
    最近更新 更多