0

将地址发回 POST 方法。我想向该地址发送电子邮件:

 [HttpPost, ActionName("Index")]
    public ActionResult IndexPOST(SuppliersIndexVM allSuppliers)
    {
        MailMessage mail = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

        mail.From = new MailAddress("martin.lagan@umac-solutions.co.uk");
        mail.To.Add("martin.lagan@umac-solutions.co.uk");
        mail.Subject = "Order";
        mail.Body = "I would like to order the following...";

        SmtpServer.Send(mail);

        return RedirectToAction("Index");
    }

错误来自最后一行:SmptpServer.Sed(mail)...

SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应是: 5.7.0 必须首先发出 STARTTLS 命令。b20sm10938791wiw.4 - gsmtp

任何想法,伙计们......还有我如何在我发送的电子邮件中添加表格等......干杯

4

1 回答 1

0

我认为该错误是由于 Gmail 需要身份验证才能允许您通过其 SMTP 服务器发送电子邮件。您可以尝试添加以下代码来解决此问题。

SmtpServer.EnableSsl = true;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("emailaddress","password");
于 2013-07-17T17:04:26.383 回答