[英]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.