1

I think that Gmail is rewriting the from address and using the account that is provided in the network credentials for the from.

    MailMessage message = new MailMessage();
    message.From = new MailAddress("jimmy@gmail.com");
    message.To.Add(new MailAddress("myacct@gmail.com"));
    message.Subject = "[Yep] Contact Form";
    message.Body = msg;
    message.IsBodyHtml = false;

    SmtpClient client = new SmtpClient();
    client.UseDefaultCredentials = false;
    NetworkCredential networkCredentials = new NetworkCredential("myacct@gmail.com", "pass");
    client.Credentials = networkCredentials;
    client.EnableSsl = true;
    client.Host = "smtp.gmail.com";
    client.Port = 587;

    try
    {
        client.Send(message);

This is the received email:

From: myacct@gmail.com To: myacct@gmail.com Date: Sun, 23 Sep 2012 14:44:54 -0700 (PDT) Subject: [Yep] Contact Form Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable

This is a test

I know it use to work but now the from is always mine. Can I get a confirmation if everyone else is having this issue or is it just me?

Zippy
  • 455
  • 1
  • 11
  • 25
  • Hopefully it's everybody. There's no legitimate reason to do this. – Tony Hopkinson Sep 23 '12 at 21:55
  • well when I have a webform and they enter their email I can set it to be the from. Therefore, when I receive it I can just reply. Yes it is a legitimate reason. So I will have to turn on my own SMTP server. Gmail use to allow this functionality back in 2009 because I use to host a site that used it as described. – Zippy Sep 23 '12 at 22:13
  • Maybe, I'd have found a different solution though. Manipulating the From address is a spammer trick. I don't like being confused with that sort of person. – Tony Hopkinson Sep 23 '12 at 23:37
  • @Tom Right, You can still achieve similar functionality with your custom SMTP server. When you send acknowledgement response to the visitor Keep the email from which you're going reply into BCC. Then use Reply To All, delete SMTP server id from the TO list., this should do the trick. – Abhijeet Sep 23 '12 at 23:40

3 Answers3

2

GMail (and many other email providers) will not allow you to alter the FROM header. That would allow email spoofing.

Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • When you are authenticating you are accepting the terms of use. So either I send using code or send using gmail or outlook I fall under the terms of use. If I violate the terms I am responsible and they can shut off the email. In addition they have a daily limit of outbound emails that can be sent. This concept is not old and is called SMTP relay. I think they are not allowing this from their servers anymore unless I am doing something incorrect. It has been awhile since I used net.mail. – Zippy Sep 23 '12 at 22:18
  • @Tom What about the TOC with your users, it's their email address you are using. – Tony Hopkinson Sep 23 '12 at 23:40
  • @Tom: SMTP relay is a gateway for quite a bit of spam. Whether or not you are within the TOC, they presumably don't want to deal with whether you are authorized to relay or not. – Eric J. Sep 25 '12 at 21:46
1

To achieve this result you will have to go for custom email provider like godaddy or buy business subscription from gmail.

You can also refer Sending Mail from Windows Azure Service, using Godaddy SMTP

Community
  • 1
  • 1
Abhijeet
  • 13,562
  • 26
  • 94
  • 175
  • Thanks, I have a virtual server and will enable SMTP on it. It was always less overhead if I used gmail as it is reliable and avail for use. – Zippy Sep 23 '12 at 22:19
1

Dim attachmentFile As String = Nothing If FileUpload1.HasFile Then

        Try
            FileUpload1.SaveAs("C:\files\" + FileUpload1.FileName)
            attachmentFile = FileUpload1.PostedFile.FileName
        Catch ex As Exception
            litStatus.Text = "File Upload Failed !! " + ex.Message.ToString()
        End Try


        Try
            Dim mail As New MailMessage()
            Dim SmtpServer As New SmtpClient("smtp.gmail.com")

            mail.From = New MailAddress("your-gamila-ddress@gmail.com")




            'you have to provide your gmail address as from address'
            mail.[To].Add(txtTo.Text)
            mail.Subject = txtSubject.Text
            mail.Body = txtBody.Text

            Dim attachment As System.Net.Mail.Attachment
            attachment = New System.Net.Mail.Attachment(attachmentFile)
            mail.Attachments.Add(attachment)

            SmtpServer.Port = 587
            SmtpServer.Credentials = New System.Net.NetworkCredential("gamil-username", "gmail-passowrd")


            'you have to provide you gamil username and password'
            SmtpServer.EnableSsl = True
            SmtpServer.Send(mail)
            litStatus.Text = "Email successfully sent."
        Catch ex As Exception
            litStatus.Text = "Mail Send Failed ! " + ex.Message.ToString()
        End Try

    Else
        litStatus.Text = "Please select a file for uploading"
    End If
Guji
  • 11
  • 1