MailMessage.From - how to set the address?

  • Thread starter Thread starter Richard Bogle
  • Start date Start date
R

Richard Bogle

Hi,

MailMessage.From allows me to set the email address that the message comes
from but not the "covering address" (sorry, no idea what the correct
terminology might be).

The email message should have the To: field appear as "Joe Bloggs" rather
than the plain e-mail address.

Any ideas?

Cheers,
Richard,.
 
Richard Bogle said:
Hi,

MailMessage.From allows me to set the email address that the message comes
from but not the "covering address" (sorry, no idea what the correct
terminology might be).

The email message should have the To: field appear as "Joe Bloggs" rather
than the plain e-mail address.
Richard -

I assume you mean the descriptive text that is seen next to the
real e-mail address, such as:

From: Joe Bloggs <joe_bloggs@someplace>

To do this you must create a custom From header instead of just
using the standard From property of the MailMessage object:

Mailmessage mm = new MailMessage();
mm.To = anotherguy@someotherplace
mm.Headers.Add("From", "Joe Bloggs <joe_bloggs@someplace>");
mm.Subject = "Test message";
mm.Body = "This is a test";
SmtpMail.Send(mm);

Hope this helps solve your problem.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471433012.html
 
Back
Top