我正在尝试将邮件从我的应用程序发送到用户输入的不同收件人。
我的模特班,
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
我不确定这是正确的方法。请帮我。
谢谢,