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:
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.