必须指定一个发件人地址,我需要帮忙

时间:2017-02-17 01:56:00

标签: c# email send

我在运行应用程序时遇到错误“必须指定来自地址的A”这段代码有什么问题,我是否需要激活某些内容?

public ActionResult contactProcess(string nombre, string apellido, string email, string consulta)
    {
        var nombreCompleto = nombre.ToUpper() + " " + apellido.ToUpper();

        MailMessage message = new MailMessage();
        message.To.Add(email);
        message.Subject = "Solicitud Procesada";
        message.Body = "Gracias por contactarnos, estaremos poniendonos en contacto con ustes en la mayor breveda posible";
        message.IsBodyHtml = true;

        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("user@gmail.com", "1234qwer");
        smtp.EnableSsl = true;
        smtp.Send(message);

        ViewBag.gracias = "Gracias por contactarnos" + nombreCompleto;
        ViewBag.texto = "hemos enviado un correo a la dirección" + email;
        return View("/Views/Formularios/contactResponse");


    }

1 个答案:

答案 0 :(得分:0)

您必须指定From地址,您可以使用构造函数。尝试以下方法:

string toMail = "you@yourDomain.com";
string fromMail = "friend@friendsdomain.com";
MailMessage message = new MailMessage(fromMail, toMail);

查看MailMessage课程中可用的构造函数以获取更多详细信息

相关问题