Reputation: 503
I am trying to send e-mails with VB.net and I have a template for the code but I don't understand a few lines.
SmtpServer.Credentials = New Net.NetworkCredential("[email protected]", "password")
mail.From = New MailAddress("[email protected]")
mail.To.Add("TOADDRESS")
As far as I understand, mail.From is the sender's name, and mail.to.add is the person I am sending to. What does smtpServer.Credentials
do?
I deduce that SmtpServer.Credentials
is the only one that requires a password so that will be the account the e-mail will be sent from. But then what is the point of mail.From
? What happens if I put different e-mails in credentials
and mail.From
.
Thanks for the help in advance!
Upvotes: 1
Views: 138
Reputation: 17194
Yes...SmtpServer.Credentials
will take the login credentials that it sends the email from that id-password...but it also provides the feature that you can add any email id in mail.From
so that will be shown in the From
part (Display purpose) of the mailbox. so it only shows that id in From
part but the actual mail comes from the one you define in credentials.
I think this will be helpful to you..!!
Upvotes: 0
Reputation: 2493
mail.From is used for display purpose. When the receive hit Reply it will add mail.From in the display name and SmtpServer.Credentials in the email address. You can alternatively also set the Reply-To address.
Upvotes: 0
Reputation: 57583
SmtpServer.Credentials
must be used only if your provider needs authentication to send email.
You can read it here
Some SMTP servers require that the client be authenticated before the server will send e-mail on its behalf. To use your default network credentials, you can set the
UseDefaultCredentials
to true instead of setting this property. If theUseDefaultCredentials
property is set to false, then the value set in the Credentials property will be used for the credentials when connecting to the server. If theUseDefaultCredentials
property is set to false and the Credentials property has not been set, then mail is sent to the server anonymously.
From
is used by receiving client as the address to send replies to.
Upvotes: 1