0

我正在为客户创建一个联系表格,以便在表格中输入信息并向我们提交电子邮件。此外,我的托管包在 Go Daddy 下。我使用以下代码作为测试并且它有效。

MailMessage oMail = new System.Web.Mail.MailMessage();

      oMail.Subject = "Subject",
      oMail.Body 
      oMail.From = "myFromAddress@domain.com",
      oMail.To = "myToAddress@someotherdomain.com",

SmtpMail.SmtpServer = "relay-hosting.secureserver.net";
SmtpMail.Send(oMail);

然后我更改了代码以获取从要通过电子邮件发送的表单中输入的信息,而不是给我一个错误。

public ActionResult ContactForm(ContactModel emailModel)
    {
        MailMessage oMail = new System.Web.Mail.MailMessage();

            oMail.From = "Website Contact Form";
            oMail.To = "myemail@hmydomain.com";
            oMail.Subject = emailModel.Subject;
            string body = "Name: " + emailModel.Name + "\n"
                        + "Email: " + emailModel.Email + "\n"
                        + "Website: " + emailModel.Website + "\n"
                        + "Phone: " + emailModel.Phone + "\n\n"
                        + emailModel.Message;

            oMail.Body = body;

    SmtpMail.SmtpServer = "relay-hosting.secureserver.net";
    SmtpMail.Send(oMail);
        return View();
    }

它给了我这个错误

COMException (0x8004020d): From 或 Sender 字段中至少有一个是必需的,但都没有找到

4

2 回答 2

1

看起来您没有提供 email-from 字段:

oMail.From = "someEmail@someDomain.com"; //instead of -> "Website Contact Form"
于 2012-01-31T18:59:36.697 回答
0

您指定的“发件人”字段不是有效的电子邮件地址。往返需要采用电子邮件格式,即使它们不是可以发送或接收邮件的实时地址。

于 2012-01-31T19:10:41.490 回答