我正在用作我的域的 SMTP 服务器。
我创建了一个“联系我们”页面,用户可以从该页面向公司发送电子邮件。
当我从计算机发送电子邮件时,它可以工作,但是人们向我抱怨说,当他们发送电子邮件时,他们会收到以下消息:
Mailbox unavailable. The server response was: 5.7.0 Mail sending denied abcdefghi
这是我的设置,
网络配置:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="info@company.com">
<network defaultCredentials="false" host="smtp.gmail.com" port="587"
userName="info@company.com" password="mypassword" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
行动:
public ActionResult Contact(ContactFormModel contact)
{
ViewBag.Message = false;
if (ModelState.IsValid)
{
var message = new MailMessage();
var sender = new MailAddress(contact.Email, contact.FullName);
message.Sender = sender;
message.From = sender;
message.To.Add(Settings.Default.ContactUsEmail);
if (contact.SendSelfCopy)
message.CC.Add(sender);
message.ReplyToList.Add(sender);
message.Subject = string.Format("Company Website - Msg from {0}: {1}",
contact.FullName, contact.Subject);
var sb = new StringBuilder();
sb.AppendFormat("From: <a href='mailto:{1}'>{0}</a>: <b>{2}</b><hr/>",
sender.DisplayName, sender.Address, contact.Subject);
sb.AppendLine(contact.Message);
message.Body = sb.ToString();
message.IsBodyHtml = true;
using (var client = new SmtpClient())
{
client.Timeout = 15000;
try
{
client.Send(message);
}
catch (Exception)
{
throw;
}
}
ModelState.Clear();
ViewBag.Success = true;
ViewBag.Message = Settings.Default.ContactUsSuccessMessage;
return View();
}
return View(contact);
}
该网站托管在 Windows Azure 中,并使用 .NET 4.5 运行。