I was helping one of the customers on a proof of concept (POC) for an InfoPath based Office Business Application (OBA) and came across a feature request to display InfoPath from inline with the email message in Outlook. Providing a consistent user experience is the reason cited for that feature. I did buy into the idea as it saves a few additional clicks to display the form before filling information like expenses, order requests, etc.
I thought I am sure people on the Internet would have done that and the solution was only a few searches away :(
No matter what I did the InfoPath form always used to come as an attachment and the user was required to open it in an InfoPath instance outside Outlook. I had to make a few phone calls to Redmond and verify through Office guys to figure out a solution and I thought this will be very helpful to share it with the community.
The solution was very simple I was missing a few vital MIME types:(
Here is a sample code (not fit for production) that uses SMTP service to generate an email on the server...
public interface IFormMailer
bool MailInfoPathForm(string from, string to, string smtpServer,
string templateName, string formName );
When an email is generated one needs to assume that the template (.XSN) will not be on the client machine and hence both .XSN and .XML files will need to be attached. While inserting the files into the mail message, it is necessary to attach appropriate MIME types. In addition to the MIME types, necessary message headers will have to be added to make sure that Outlook treats the attachments with due processing.
Following is a simple table that lists the headers and MIME types:
InfoPath File Type
Mail Message Header
Above simple WCF contract is implemented in a skeletal FormMailer class shown below:
public class FormMailer : IFormMailer
public bool MailInfoPathForm(string from, string to, string
smtpServer, string templateName, string formName)
string rootPath = @"D:\Working\InfoPathMailer\";
SmtpClient client = new SmtpClient(smtpServer);
// Make sure that your .NET thread is running under
// appropriate credentials to connect to the SMTP service
client.Credentials = CredentialCache.DefaultNetworkCredentials;
// Specify the e-mail sender.
MailAddress sender = new MailAddress(from);
// Set destinations for the e-mail message.
MailAddress receiver = new MailAddress(to);
// Specify the message content.
MailMessage message = new MailMessage(sender, receiver);
message.Subject = "InfoPath test from a web service";
// The following two lines are very important to render the
// the InfoPath form inline with the Outlook message
Attachment template = new Attachment(rootPath + templateName, new
Attachment form = new Attachment(rootPath + formName, new
// wire up an event handler for post processing
client.SendCompleted += new
catch (Exception e)
//do some logging for root cause analysis
private void SendCompletedCallback(object sender,
//do some logging and post processing here
While the above solution displays the form inline with the email message, it still doesn't display it in the preview mode. I will make another post once I figure that one out.
Hope this is helpful!
PingBack from http://msdnrss.thecoderblogs.com/2008/03/18/how-to-display-infopath-forms-inline-with-outlook-email-message/
I have a custom form region attached to a custom message class, say "IPM.Note.Test". What message headers should I set through SmtpClient to set the message class for the outgoing messages and make outlook display my form region automatically?
Great ! really helpful, Thanks !
Sharepoint forms cannot be connected to Outlook 2010. When I try to Connect to Outlook, the outlook folder will just display .xml data and not a clear rendering of the form.Any ideas why this doesn't work?
yeah i have the same issue with info path forms, there seems to be no preview handler for the infopath forms ~ kind of annoying :) it would be great if MS own products came with preview handlers :)
This works great. BUT does anyone know how to modify the Introduction field in the email message using this technique?
I read you blog with great interest, but I'm not really sure what you mean by inline. Does this mean you do not need an instance of InfoPath to fill out the form. I currently have an Outlook form whose functionality is coded with VBscript. The whole thing works to some extent but it's not very stable. So O though I'd switch to InfoPath, hoping I can design a form that when published on a server, can be opened and filled out via Oiutlook and then sent to a recipient as an e-mail, who can then process the form data as required. Is this possible?