30 October, 2013

.Net: Sending email with AlternateView, LinkedResources: System.Net.Mail

Recently we faced an issue in receiving mails from same (sender) domain email account but using different SMTP server. Mail body has few resources like GIF, JPEG and they are loaded with AlternateView (System.Net.Mail.MailAddress.AlternateViews) parameter with linked resources. 

Ex: sends mail to using a different SMTP server (ex: i.e. not using (SMTP) domain.
Result of this scenario: Receiver did not receive any email. 

In mail body, resources can be loaded with the below options.

The mail could be blocked due to Exchange Intelligent Message Filter as in Microsoft Exchange server. Also to note that emails to other providers like GMAIL, YAHOO were successful.

When we remove all the resources in the email body, email reached the destination mail boxes but without any resources. Initially, to get the resource image, the below line was used.

LinkedResource image = new LinkedResource(imageResource) { ContentId = contentId };

We did a small tweak to add proper content type for the resource which apparently resolved the issue. 

LinkedResource image = new LinkedResource(imageResource, MediaTypeNames.Image.Gif) { ContentId = contentId };

By this way, we are explicitly defining the content type of the resource. Of-course, we can simply disable the filter in the exchange server to receive the email but amending the resources in the mail body with proper content type has been skipped by the exchange filters. 

No comments:

Post a Comment

blockquote { margin: 0; } blockquote p { padding: 15px; background: #eee; border-radius: 5px; } blockquote p::before { content: '\201C'; } blockquote p::after { content: '\201D'; }