Email Reports

  • 2 minutes to read

This document describes how to send an exported report by e-mail.

  • Use the report's ExportOptions.Email property to specify options for report export.
  • Invoke an ExportToMail overloaded method report to convert a report to a MailMessage object (an HTML representation of the report).
  • Initialize an SmtpClient and call its Send or SendAsync method to send the message.

To send a report to several recipients, add recipients to the recipients collection stored in the EmailOptions.AdditionalRecipients property:

To add or insert a new recipient to the AdditionalRecipients collection, use the EmailOptions.AddRecipient or EmailOptions.InsertRecipient methods with a Recipient parameter.

The Recipient class is used to contain the recipient settings:

using DevExpress.XtraPrinting;
// ...

private void button1_Click(object sender, EventArgs e) {
    XtraReport1 report = new XtraReport1();

    // Add an array of recipients to the collection. 
    Recipient[] array = new Recipient[] {
        new Recipient("FirstRecipient@somewhere.com", "First Recipient", RecipientFieldType.TO),
        new Recipient("SecondRecipient@somewhere.com", "Second Recipient", RecipientFieldType.TO), 
        new Recipient("CopyRecipient@somewhere.com", "Copy Recipient", RecipientFieldType.CC)
    };
    report.ExportOptions.Email.AdditionalRecipients.AddRange(array);
}
See Also