【问题标题】:A From address must be especified, i need hel on this please必须指定发件人地址,我需要帮助
【发布时间】:2017-07-06 09:31:28
【问题描述】:

运行应用程序时出现错误“必须指定来自地址的地址”此代码有什么问题,我需要激活一些东西吗?

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");


    }

【问题讨论】:

  • 您没有输入自己的电子邮件地址。应该是这样的MailMessage msg = new MailMessage { From = new MailAddress(EmailAddress, DisplayName, Encoding.UTF8) };

标签: c# email send


【解决方案1】:

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

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

查看MailMessage 类中可用的构造函数了解更多详情

【讨论】:

    猜你喜欢
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    相关资源
    最近更新 更多