简体   繁体   中英

Sending an email in VB.Net / C# Form

In VB.Net (Or C#) when I create the code to send out an email, I always set the "sender" to an email on my server instead of the email of the person who's filling the form.

Little example:

System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()

mailMessage.From = New System.Net.Mail.MailAddress("someone@domain.com")

mailMessage.To.Add(New System.Net.Mail.MailAddress("someone@domain.com"))

This is important because most hosting providers restrict using an email which relies outside of your hosting environment to send out an email (security purposes which I totally understand).

The above works really well, but the problem is when someone wants to reply to the email, they are actually going to be replying to their own email address, unless they manually copy the email of the person from the content of the message and put it in the "To" field while replying.

I would like to know what are the best practices today in order to deal sending emails.

I see some emails I get with "On Behalf Of" and others with "Reply To".

Is there anything else I am missing here? Please advice.

Working with SMTP MailMessage, i always use ReplyTo and it works:

rawMessage.ReplyTo = New MailAddress("someoneElse@domain.com");

But for outlook Interop, it's the OnBehalfOf...

EDIT:

As you are using vs2010, ReplyTo is obsolete, ReplyToList may be used:

rawMessage.ReplyToList.Add("someoneElse@domain.com");

EDIT:

Sorry I misunderstood the original question - actually it's looking for the difference between the two: OnBehalfOf and ReplyTo,

as far as I know, at the MailMessage object, if you set Sender with a different email address other than the From address, the client (outlook for instance) will show "On Behalf Of".

but if you set the ReplyTo, the client would not show that, instead, it populates the To field automatically if user clicks Reply/ReplyAll

it really depends on your needs to decide which one to use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM