Partager via


MailEnvelope Class

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

Inheritance Hierarchy

System.Object
  Microsoft.Office.InfoPath.MailEnvelope

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

Syntax

'Declaration
Public MustInherit Class MailEnvelope
'Usage
Dim instance As MailEnvelope
public abstract class MailEnvelope

Remarks

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.

Note

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.

Examples

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 = "someone@example.com";
   myEnvelope.CC = "someone@example.com";
   myEnvelope.BCC = "someone@example.com";
   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;
}
else
{
   // The form is open in Outlook, and code will not run.
   MessageBox.Show("This form is open in Outlook.");
}
' Set a reference to MailEnvelope object.
Dim myEnvelope As MailEnvelope  = _
   Me.Application.ActiveWindow.MailEnvelope

' Check to see if form is open in Outlook.
If (myEnvelope.Available) Then
   ' Specify addresses, subject, and introduction.
   myEnvelope.To = "someone@example.com"
   myEnvelope.CC = "someone@example.com"
   myEnvelope.BCC = "someone@example.com"
   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
Else
   ' The form is open in Outlook, and code will not run.
   MessageBox.Show("This form is open in Outlook.")
End If

Thread Safety

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

See Also

Reference

MailEnvelope Members

Microsoft.Office.InfoPath Namespace