简体   繁体   English

使用System.Net.Mail.SmtpClient,更改SMTP FROM电子邮件地址

[英]Using System.Net.Mail.SmtpClient, change the SMTP FROM email address

As it says in the title, I wish to change the FROM address provided to the SMTP server, as opposed to the FROM address in the email envelope. 如标题中所述,我希望更改提供给SMTP服务器的FROM地址,而不是电子邮件信封中的FROM地址。

The closest sample I can find is from Java, which is can be found here 我可以找到的最接近的样本来自Java, 可以在这里找到

Thanks 谢谢

The FROM provided to the SMTP server is the login of the SmtpClient while the one in the Mail is the FROM in the MailMessage. 提供给SMTP服务器的FROM是SmtpClient的登录名,而邮件中的那个是MailMessage中的FROM。

SmtpClient smtp = new SmtpClient();
smtp.Host = "myserver.address.com";
smtp.Credentials = new NetworkCredential("me@server.com", "myPassword");

MailMessage msg = new MailMessage();
msg.From = "otherMe@server.com";

//OTHER MESSAGE SETTINGS

smtp.Send(msg);

This should send an e-mail from "otherMe@server.com" using the authentication on the server for the user "me@server.com" 这应该使用服务器上针对用户“ me@server.com”的身份验证从“ otherMe@server.com”发送电子邮件。

The Java example is about return address, not From. Java示例是关于返回地址,而不是发件人。

As Far as I know, you can't do this. 据我所知,您不能这样做。 SMTP servers use the From address to decide if the want to relay or not. SMTP服务器使用“发件人”地址来决定是否要中继。

The only other credential you've got is the Login to the SMTP server. 您获得的唯一其他凭据是SMTP服务器的登录名。

Bottom line is, you can't do this. 最重要的是,您不能这样做。 The FROM address used in System.Net.Mail is used for both the SMTP transaction (Envelope-From) and the MailMessage from header value. System.Net.Mail中使用的FROM地址用于SMTP事务(Envelope-From)和MailMessage from标头值。

Sorry, 抱歉,
Dave 戴夫

As explained by bzlm , if you're using Network delivery method of SmtpClient, then you can set MAIL FROM by setting the MailMessage.Sender property. bzlm所述 ,如果您使用的是SmtpClient的网络传递方法,则可以通过设置MailMessage.Sender属性来设置MAIL FROM。 Note, however, that this will have the side-effect of adding a Sender heady to your message, which will cause many email clients to display present the message sender as "X on behalf of Y". 但是请注意,这样做会产生副作用,即在邮件中添加发件人标题,这将导致许多电子邮件客户端将邮件发件人显示为“ X代表Y”。

Unfortunately, this is not possible. 不幸的是,这是不可能的。

First there is a syntax error for smtp.Host = smtp.serv.com; 首先, smtp.Host = smtp.serv.com;存在语法错误smtp.Host = smtp.serv.com; This is not valid written string type, and the second thing is that the property Host doesn't exist. 这是无效的书面字符串类型,第二件事是属性Host不存在。

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

相关问题 使用System.Net.Mail.SmtpClient发送的电子邮件的字体大小 - Font size for an email sent using System.Net.Mail.SmtpClient 使用System.Net.Mail.SmtpClient将电子邮件发送到通讯组列表 - Sending email to a distribution list using System.Net.Mail.SmtpClient 如何在Xamarin中使用System.Net.Mail.SmtpClient发送邮件 - How to send a mail in Xamarin using System.Net.Mail.SmtpClient 无法使用 System.Net.Mail.SmtpClient 将 email 发送到其他域 - Unable to send email to other domains using System.Net.Mail.SmtpClient System.Net.Mail.SmtpClient 在 4.7 中过时了吗? - Is System.Net.Mail.SmtpClient obsolete in 4.7? 第三方与System.Net.Mail.SmtpClient - Third-party vs System.Net.Mail.SmtpClient 发送到 System.Net.Mail.SmtpClient 等文件夹 - Send to folder like System.Net.Mail.SmtpClient 如何使用TLS和System.Net.Mail.SMTPCLient连接到googlemail.com? - How can I connect to googlemail.com using TLS and System.Net.Mail.SMTPCLient? System.Net.Mail.SmtpClient 在发送电子邮件时使用什么类型的身份验证? - What type of authentication is System.Net.Mail.SmtpClient using when sending emails? 使用TLS和SmtpAuth在.Net 4 / C#中发送带有System.Net.Mail.SmtpClient的电子邮件,可在本地使用,但不能在生产服务器上运行(win 2008 r2) - Sending email with System.Net.Mail.SmtpClient in .Net 4/C# with TLS and SmtpAuth, works locally but not on production server(win 2008 r2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM