# MailEnvelope Object

MailEnvelope

Represents a custom e-mail message in a Microsoft Office InfoPath 2003 form. The MailEnvelope object provides a number of properties that can be used to programmatically create a custom e-mail message within the default e-mail editor, and it attaches the currently open InfoPath form to the message.

## Remarks

After the e-mail message is created, the default e-mail editor will display the e-mail message; users can then inspect and edit the e-mail message before sending it.

Note The MailEnvelope object cannot be used to send the e-mail messages it creates; users must manually send the e-mail messages.

You can also use the ShowMailItem method of the UI object to programmatically create e-mail messages.

## Using the MailEnvelope object

The MailEnvelope object is accessed through the MailEnvelope property of the Window object.

In the following example from the Meeting Agenda sample form, the MailEnvelope property of the Window object is used to set a reference to the MailEnvelope object that is associated with the currently active window. The code then uses the MailEnvelope object to create a custom e-mail message.

    function SendMeetingAgendaBtn::OnClick(oEvent)
    {
       var rgRecipients = new Array();
       var xmlRecipients = getNodeList("/mtg:meetingAgenda/
          mtg:attendees/mtg:attendee/mtg:emailAddressPrimary");
       var xmlRecipient;

       while (xmlRecipient = xmlRecipients.nextNode())
          rgRecipients.push(xmlRecipient.text);

       try
       {
          var oEnvelope = Application.ActiveWindow.MailEnvelope;

          oEnvelope.Subject = getNode("/mtg:meetingAgenda/mtg:subject").text;
          oEnvelope.To = rgRecipients.join("; ");
          oEnvelope.Visible = true;
       }
       catch(ex)
       {
          XDocument.UI.Alert(ex.description);
       }
    }

©2003-2004 Microsoft Corporation. All rights reserved. Permission to copy, display and distribute this document is available at: http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp