views:

172

answers:

2

I need to remove SMTP headers from from System.Net.Mail.MailMessage. Specifically, headers that contain information about the environment MailMessage originates from.

I have tried inspecting the MailMessage just before it is sent by SmtpClient, but no headers were set (they are set at a later stage).

Can this be done in .NET Framework 3.5 or do I need a 3rd-party SMTP library?

Edit: This is something that has been requested by the hosting company that hosts the website I'm working on. They say this is needed to protect information about the internal network layout.

Is this generally considered to be bad practice? What are the potential side-effects?

+1  A: 

Can you specify the PickupDirectoryLocation property (see http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.pickupdirectorylocation.aspx) instead of using the SMTP server IP? Then loop through the generated emails, remove the header items, then copy over to the SMTP incoming directory? You'll need to ask your web host if you can copy files into their SMTP server incoming directory to see if they might support this method.

I can somewhat understand their concerns, but I've never heard of this happening before. At least not by a developer. It seems like it's something their SMTP host should be capability of doing. I could assume they'd like to hide the name of their SMTP host or mail server software versions, etc. But I don't even know if it's possible to do such because I always assumed those headers were added by the SMTP host and not by any code we (as developers) would write.

Jim W
Thanks Jim W. I will investigate further.
Arnold Zokas
A: 

I did a few more tests and it looks like the headers in question are generated by the SMTP server and NOT by .NET Framework.

Arnold Zokas
That's what I had always assumed. Thanks for the confirmation.
Jim W