How to add custom headers to System.Net.Mail? When sending an email using the MailMessage class (System.Net.Mail namespace) in an ASP.NET website, certain email headers like
Message-ID are not always set. When a Message-ID header is missing, email might be blocked by the recipients SMTP server. Therefore it is necessary to set such headers…
The System.Net.Mail Namespace allows you to send authenticated SMTP email over TLS. Unfortunately, System.Net.Mail leaves out the mandatory Message-ID header. Here is how you can add this important header to your email. You can set a Message-ID, or any other custom header with the
Message.Headers property and
Message.Headers.Add( "Message-Id", "<" + Guid.NewGuid().ToString() + "@example.com>" );
Change example.com with your own domain name.
You can use this for other, custom headers as well, for example:
Message.Headers.Add( "X-Instance-ID", Convert.ToString( InstanceID ) );
My name is Jan. I am not a hacker, coder, developer, programmer or guru. I am merely a system administrator, doing my daily thing at Vevida in the Netherlands. With over 15 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, WordPress, websites & optimization. Want to support me and donate? Use this link: https://paypal.me/jreilink.