Mailmessage.from not working as expected

1.4k views Asked by At

thanks in advance for any help!

I want it so when [email protected] receives the email it appears to be coming from [email protected]. I believed this would work but it continues to appear to come from [email protected]. I've attempted to use ReplytoList/Headers but with no luck any help would be much appreciated.

using (var client = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                Credentials = new NetworkCredential("[email protected]", "$$$$$"),
                DeliveryMethod = SmtpDeliveryMethod.Network
            })
            {
                var mail = new MailMessage();
                mail.To.Add(new MailAddress("[email protected]")); 
                mail.From = new MailAddress("[email protected]");
                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

There are 1 answers

5
meda On

This is because you need to add the [email protected] in to your [email protected] account as an alternative email address, otherwise gmail smtp server won't let you spoof the email address.

enter image description here