14.2. Sending a Form in an E-Mail

Another useful feature is to be able to send forms to other users via e-mail. While you can accomplish this using the menu choices, it is also more professional and convenient to be able to create code to accomplish the same thing.

To send a form using e-mail, you will need to perform a couple of steps: First, you need to create a data connection for your form, but in this case it will be used for sending e-mail instead of submitting and retrieving data to and from a database. You can see the Data Connection Wizard used for setting up the data connection in Figure 14-7.

Figure 14.7. Figure 14-7

Although you have to specify someone for the To field when creating the data connection, you can change all the properties using code at runtime.

The next step is to create the form you want to send. Finally, you have to write the necessary code, added to a command button on the form. The code created will use a DataAdapter from the DataAdapters collection off the XDocument object. You can see the line of code here:

var objEmail = XDocument.DataAdapters("Submit");

Because you set the data adapter up to work with e-mail, InfoPath knows how to use it. The following table contains some of the properties for the Email Adapter:

PropertyDescription
AttachmentFileNameSets or returns the name of the attachment that will be made of the for.
BCCBCC recipient
CCCC recipient ...

Get Beginning InfoPath™ 2003 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.