1

我正在尝试将邮件从我的应用程序发送到用户输入的不同收件人。

我的模特班,

public class Mail
 {
    public int MailId { get; set; }

    public string Mail_To { get; set; }

    public string Mail_From { get; set; }

    public string Mail_Subject { get; set; }

    public string Mail_Contents { get; set; }

    public DateTime Mail_Date { get; set; }

    [ForeignKey("Anganwadi")]
    public int AnganwadiId { get; set; }
    public virtual Anganwadi Anganwadi { get; set; }
}

我的控制器看起来像,

[HttpPost]
    public ViewResult SendMail(Mail mail) 
    {
        try
        {
if (ModelState.IsValid)
            {
                mail.Mail_Date = System.DateTime.Now;
                mail.AnganwadiId = 1;
                mail.Mail_From = "k@gmail.com";
                mail.Mail_Subject = "From Anganwadi";
                MailMessage message = new MailMessage();
                message.From = new MailAddress(mail.Mail_From);
                message.To.Add(new MailAddress("v@gmail.com"));
                message.Subject = mail.Mail_Subject;
                message.Body = mail.Mail_Contents;

                SmtpClient client = new SmtpClient();
                client.Send(message);
                return View("Thanks", mail);
            }
            else
            {
                return View();
            }
        }
        catch (Exception e)
        {
            return View(e);
        }
    }

在我的网络配置中,我添加了以下内容

<system.net>
  <mailSettings>
    <smtp from="test@foo.com">
      <network host="smtp.efernssolutions.com" port="587" defaultCredentials="true" />
    </smtp>
  </mailSettings>
</system.net>

收到错误

Mailbox unavailable. The server response was: authsmtp12: Host 117.196.165.214: No unauthenticated relaying permitted

我不确定这是正确的方法。请帮我。

谢谢,

4

1 回答 1

1

from="test@foo.com"在 smtp 配置中使用它而不是代码中的地址。此电子邮件在其域中包含无效的 MX 记录 ( http://www.digwebinterface.com/?hostnames=foo.com%0D%0A&type=ANY&useresolver=8.8.4.4&ns=auth&nameservers= )

即使进行测试,您也应该更好地使用现有的电子邮件。

于 2012-11-29T06:00:38.460 回答