VS.NET 2010 (and above) Users Click Here   

Licensing FAQ
Software Updates
Support Forums
Feature Requests
About Us
Contact Us
Hosting Companies
Privacy Policy
Shopping Cart


RSS feed for aspNetDkim Subscribe to category: aspNetDkim

DKIM and an IIS SMTP Service Mail Merge

by Dave 2. June 2011 03:30

I recently had a request on how to perform an IIS SMTP service mail merge with aspNetDkim.

This is actually pretty straightforward, with 1 minor, but important exception.

By default, the IIS SMTP service adds a date/time stamp to the emails. This will actually break DKIM strict signatures. To get around this, aspNetEmail has the option to automatically add this date/time header to the email.  IIS SMTP service will recognize the header, and not try to insert it's own IIS header.

So, once we specify that option, the only other minor work we have to do, is tie into the RenderEmailContents event. Once we tie into that event, we get access to the (you guessed it) rendered contents of the email.  We then sign these contents, and override the contents that would be used by aspNetEmail for ending to the IIS SMTP pickup directory.

Below is a code example of how to do this.


		private  void IisSmtpMerge()
			EmailMessage msg = new EmailMessage();
			msg.Subject = "Order Confirmation";
			msg.To = "##EmailAddress##";

			msg.From = "me@myCompany.com";

			//logging for easier troubleshooting
			msg.Logging = true;
			msg.LogPath = "c:\\email.log";

			//set the plain text body
			msg.Body  = "Hi ##EmailAddress##, \r\nhere you go...";

			//add some custom X-Headers
			msg.AddHeader( "X-Company", "Acme Corp" );
			msg.AddXHeader( "X-FirstName", "##fldFirstName##" );

			//add the render event, so we can sign the message
			msg.RenderEmailContents += new RenderEmailContentsEventHandler( OnRenderEmail );

			//a method that gets our mail merge data
			DataTable dt = GetDataTable();

			//create an instance of the IISSmtp object
			IISSmtp iis = new IISSmtp( msg );

			//add the arrival time, so IIS doesn't (which would break the DomainKeys signature)
			iis.PickupDirectory = "c:\\temp\\";

			iis.SendMailMerge( dt );

		private  void OnRenderEmail( object sender, RenderEmailContentsEventArgs e )
			string contents = e.Contents;

			//sign the contents using a Domainkeys method
			contents = SignDomainKeys( contents );
			//or sign the contents using a Dkim method
			contents = SignDkimRelaxed( contents );

			//reset the contents
			e.Contents = contents;

Examples of the SignDK or SignDkimRelaxed methods can be found here:


If anyone has any questions, feel free to contact me using the Contact Us page.

Dave Wanta




Thanks for the quick response! I wish everyone was like that. I'm trying to get a response from [*****] and the only way to contact them is through their web site and they don't even guarantee they will respond at all. Bad support can be frustrating, hence I appreciate your history of great support immensely!! "

S.W. | Codepdx

Read more testimonials
ListNanny aspNetDNS aspNetEmail aspNetPOP3 aspNetMX IPMuncher aspNetMIME aspNetPING aspNetTraceRoute aspNetIMAP aspNetMHT