0

I am trying to send email from X@gmail.com to Y@yahoo.com using System.Net.Mail, Below is my code

Dim message As MailMessage = New MailMessage()
message.From = New MailAddress(Me.txtFromEmail.Text, Me.txtFromName.Text)
message.Sender = New MailAddress(Me.txtFromEmail.Text, Me.txtFromName.Text)
message.ReplyToList.Add(New MailAddress(Me.txtFromEmail.Text))
message.To.Add(New MailAddress(Me.txtTo.Text))
message.Subject = Me.txtSubject.Text & " " & Now.ToString

message.Body = Me.txtMessage.Text
If Me.txtCC.Text <> "" Then message.CC.Add(Me.txtCC.Text)
If Me.txtBCC.Text <> "" Then message.Bcc.Add(txtBCC.Text)

Dim mclient As SmtpClient = New SmtpClient()
mclient.Host = "smtp.gmail.com"
mclient.Port = 587
mclient.EnableSsl = True
mclient.Credentials = New System.Net.NetworkCredential("email@myapp.com", "somepassword")
mclient.Send(message)

Above code sends email without any error....

Issues: At the recipient inbox it listed as Sender Name <email@myapp.com> instead of Sender Name <x@gmail.com>

How can I set it as Sender Name <x@gmail.com>

Kartik Goyal
  • 376
  • 1
  • 6
  • 15
  • It is very likely that gmail is setting the sender to your credentials so that you cannot change the Sender. – pln Oct 08 '14 at 09:00
  • Lets replace x@gmail.com to x@test.com and replace y@yahoo.com to y@example.com can I get now as Sender Name ? If you look on the scenario, you will find that email is getting fire from "myapp.com" server but Sender & Recipient does not belong to the same server. In PHP we can send email through SMTP or without SMTP. Without SMTP it works as I am looking for. So here another question raise can we can email without SMTP – Kartik Goyal Oct 08 '14 at 10:00
  • No there is nothing built in that will let you do that and for a good reason. – pln Oct 08 '14 at 10:33

0 Answers0