开发者

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

As it says in the title, I wish to change the FROM addre开发者_如何学运维ss provided to the SMTP server, as opposed to the FROM address in the email envelope.

The closest sample I can find is from Java, which is can be found here

Thanks


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.

Sorry,
Dave


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.

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"


The Java example is about return address, not From.

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.

The only other credential you've got is the Login to the SMTP server.


Unfortunately, this is not possible.

First there is a syntax error for smtp.Host = smtp.serv.com; This is not valid written string type, and the second thing is that the property Host doesn't exist.


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. 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".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜