MailEnvelope Class

Represents a custom e-mail message for sending the current form as an attachment.


Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)

public abstract class MailEnvelope

The MailEnvelope class provides properties that can be used to programmatically create a custom e-mail message for attaching and sending the currently open InfoPath form. After any e-mail addresses and other properties are specified, setting the Visible property of the MailEnvelope class to true will display the e-mail message fields, Send toolbar, and Mail Options task pane along with the form so that users can then inspect and make any changes or additions to the e-mail message before sending it. Writing code to work with a MailEnvelope object is equivalent to using the Send to Mail Recipient command on the File menu when editing a form in InfoPath.


The MailEnvelope class cannot be used to send the e-mail messages it creates; users must manually send the e-mail messages by clicking the Send button in InfoPath.

Alternatively, you can use the ShowMailItem method of the View class to programmatically create an e-mail message with an attached form. Or, if the form template has been configured to be submitted as an e-mail message, you can use the properties and methods of the EmailSubmitConnection class to programmatically create and send the form as an e-mail attachment.

In the following example, the EmailSubmitConnection property of the Window class is used to set a reference to the MailEnvelope object for the current form. The Available property is used to determine if the form is opened within Microsoft Office Outlook 2007. If so, the Available property will return false, and the following code will not run. If the Available property returns true, the form is open in InfoPath, and the initial address, subject, and introduction values are specified. Then, the EmailAttachmentType property of the MailEnvelope class is used to configure the message to include both the form data and form template. Finally, the Visible property of the MailEnvelope class is set to true to display the e-mail message fields, Send toolbar, and Mail Options task pane to the user for sending the e-mail message from InfoPath.

// Set a reference to MailEnvelope object.
MailEnvelope myEnvelope = this.Application.ActiveWindow.MailEnvelope;

// Check to see if form is open in Outlook.
if (myEnvelope.Available)
   // Specify addresses, subject, and introduction.
   myEnvelope.To = "";
   myEnvelope.CC = "";
   myEnvelope.BCC = "";
   myEnvelope.Subject = "Open this form";
   myEnvelope.Introduction = "InfoPath is required to edit this form.";

   // Include form template with form.
   myEnvelope.EmailAttachmentType = EmailAttachmentType.XmlXsn;

   // Display form with e-mail envelope.
   myEnvelope.Visible = true;
   // The form is open in Outlook, and code will not run.
   MessageBox.Show("This form is open in Outlook.");

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.