Mailmessage.from没有按预期工作

时间:2013-08-30 21:16:31

标签: c# system.net.mail

提前感谢您的帮助!

我想要它,所以当A@gmail.com收到电子邮件时,它似乎来自B@gmail.com。我相信这会起作用,但它似乎仍然来自A@gmail.com。我试图使用ReplytoList / Headers,但没有运气任何帮助将不胜感激。

using (var client = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                Credentials = new NetworkCredential("A@gmail.com", "$$$$$"),
                DeliveryMethod = SmtpDeliveryMethod.Network
            })
            {
                var mail = new MailMessage();
                mail.To.Add(new MailAddress("A@gmail.com")); 
                mail.From = new MailAddress("B@gmail.com");
                mail.Subject = String.Format("Request to Contact from {0}", form.CompanyName);
                mail.Body = form.Message;
                mail.IsBodyHtml = false;
                try
                {
                    client.Send(mail);
                    retValue = "Your Request for Contact was submitted successfully. We will contact you shortly.";
                }
                catch (Exception)
                {

                    throw;
                }

1 个答案:

答案 0 :(得分:1)

这是因为您需要将B@gmail.com添加到A@gmail.com帐户作为备用电子邮件地址,否则gmail smtp服务器不会让您欺骗电子邮件地址。

enter image description here