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:
| Property | Description |
|---|---|
| AttachmentFileName | Sets or returns the name of the attachment that will be made of the for. |
| BCC | BCC recipient |
| CC | CC recipient ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access