1

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.

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

Thanks

Community
  • 1
  • 1
Surgical Coder
  • 1,086
  • 1
  • 16
  • 25

5 Answers5

3

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"

Brandon
  • 68,708
  • 30
  • 194
  • 223
il_guru
  • 8,383
  • 2
  • 42
  • 51
  • 1
    Iv tried this, and iv monitored the stream thats sent to the server via WireShark, and its still using the Envelope's from address as the FROM address for the SMTP. – Surgical Coder Sep 22 '10 at 11:57
3

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

dave wanta
  • 7,164
  • 3
  • 29
  • 29
  • Is it possible with AspNetEmail? – Surgical Coder Sep 22 '10 at 13:07
  • Yes. On the aspNetEmail.EmailMessage object, the value of the .ReversePath property is used during the SMTP session (envelope-from), and the .FromAddress property value is used in the actual email message. If you do not set the .ReversePath property, the .FromAddress value is used during the SMTP session. – dave wanta Sep 22 '10 at 21:18
1

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.

H H
  • 263,252
  • 30
  • 330
  • 514
-1

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

Community
  • 1
  • 1
Chris
  • 9,986
  • 8
  • 48
  • 56
-1

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.

Brandon
  • 68,708
  • 30
  • 194
  • 223