0

I have a problem with one of my forms that I've created. It is supposed to be an email sender that allows the user to send an email to a given email in the code from a specified email that they put in TextBox1. The problem is that the email, when sent to my Gmail account, does not use this custom 'from' email.

Here is my code below:

Imports System.Net.Mail

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim EmailMessage As New MailMessage()
        Try
            EmailMessage.From = New MailAddress(TextBox1.Text)
            EmailMessage.To.Add("to@gmail.com")
            EmailMessage.Subject = TextBox2.Text
            EmailMessage.Body = RichTextBox1.Text
            Dim SMTP As New SmtpClient("smtp.gmail.com")
            SMTP.Port = 587
            SMTP.EnableSsl = True
            SMTP.Credentials = New System.Net.NetworkCredential("user", "*******")
            SMTP.Send(EmailMessage)
        Catch ex As Exception

        End Try
    End Sub
End Class

And a picture of the form:

enter image description here

Can anybody help me out and make it so the "Return email:" field is the email that is used as the sender.

By the way, the subject and body fields do work correctly.

2 Answers2

1

It looks like you are setting the From property correctly. That will set the From value in the SMTP header. However, not all email clients honor that From value in the header. GMail, in particular, ignores the From value in the header and always displays the actual email account that originally sent the message. Their intent in doing so is to avoid scams where people are fooled by fake From addresses.

Steven Doggart
  • 43,358
  • 8
  • 68
  • 105
0

I don't believe google let's you replace the From: address, it will always use the logged in users SMTP alias as the From:

You might be able to use the ReplyTo/ReplyToList properties though, have never tried.

EDIT: Did some further searching and found this issue that appears to be instructions for doing exactly what you want to do.

Community
  • 1
  • 1
Eric Walker
  • 1,042
  • 10
  • 15