简体   繁体   English

以VB.Net / C#格式发送电子邮件

[英]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. 在VB.Net(或C#)中,当我创建发送电子邮件的代码时,我总是将“发件人”设置为服务器上的电子邮件,而不是填写表单的人的电子邮件。

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: 使用SMTP MailMessage时,我始终使用ReplyTo,并且它的工作原理是:

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

But for outlook Interop, it's the OnBehalfOf... 但对于Outlook Interop,它是OnBehalfOf ...

EDIT: 编辑:

As you are using vs2010, ReplyTo is obsolete, ReplyToList may be used: 在使用vs2010时,ReplyTo已过时,可以使用ReplyToList:

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, 抱歉,我误解了最初的问题-实际上,它是在寻找两者之间的区别:OnBehalfOf和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". 据我所知,在MailMessage对象上,如果将“发件人”设置为不同于“发件人”地址的其他电子邮件地址,则客户端(例如,外观)将显示“代表”。

but if you set the ReplyTo, the client would not show that, instead, it populates the To field automatically if user clicks Reply/ReplyAll 但是如果设置了ReplyTo,客户端将不会显示该消息,而是在用户单击Reply / ReplyAll时自动填充“收件人”字段

it really depends on your needs to decide which one to use. 这实际上取决于您的需求来决定使用哪个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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