Skip to main content
A newer version of this page is available. .

Email Reports

  • 5 minutes to read

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

Export to PDF and Send Email in Code

You can export a report to PDF and attach the PDF document to the email message.

For each report class you can specify different email export options in the Visual Studio Designer:

View Example: How to Email a Report as a Document in PDF

The following code exports a report to PDF, attaches the PDF document to a message, and sends the message using email options specified in the Visual Studio Report Designer.

using System;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Windows.Forms;
// ...
        // Instantiate a report. 
        // Email export options are already specified at design time.                
        XtraReport1 report = new XtraReport1();

        // Create a new memory stream and export the report in PDF.
        MemoryStream stream = new MemoryStream();

        // Create a new attachment and add the PDF document.
        stream.Seek(0, System.IO.SeekOrigin.Begin);
        Attachment attachedDoc = new Attachment(stream, "TestReport.pdf", "application/pdf");

        // Create a new message and attach the PDF document.
        MailMessage mail = new MailMessage();

        // Specify the sender and get recipient settings from the report export options.
        mail.From = new MailAddress("", "Someone");
        mail.To.Add(new MailAddress(report.ExportOptions.Email.RecipientAddress,

        // Specify other e-mail options.
        mail.Subject = report.ExportOptions.Email.Subject;
        mail.Body = "This is a test e-mail message sent by an application.";

        // Specify the SMTP server and send the message.
        string SmtpHost = null;
        int SmtpPort = -1;
        if (string.IsNullOrEmpty(SmtpHost) || SmtpPort == -1)
            throw new ArgumentException("Please configure the SMTP server settings.");

        string SmtpUserName = "Enter_Sender_User_Account";
        string SmtpUserPassword = "Enter_Sender_Password";
        SmtpClient smtpClient = new SmtpClient(SmtpHost, SmtpPort);
        smtpClient.Credentials = new NetworkCredential(SmtpUserName, SmtpUserPassword);
        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtpClient.EnableSsl = false;

        // Close the memory stream.
    catch (Exception ex)
        MessageBox.Show(this, "Error sending a report.\n" + ex.ToString());

Export to HTML Email Body

Do the following to export a report to an email message:

  • 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.

View Example: How to send a report as HTML in an email body

using System.Net;
using System.Net.Mail;
using DevExpress.XtraReports.UI;
// ...
    XtraReport report = new XtraReport1();

    string SmtpHost = "Enter_SMTP_Server_Name";
    int SmtpPort = 25;
    string SmtpUserName = "Enter_Sender_User_Name";
    string SmtpUserPassword = "Enter_Sender_Password";

    using (var smtpClient = new SmtpClient(SmtpHost, SmtpPort))
        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtpClient.EnableSsl = false;

        if (!string.IsNullOrEmpty(SmtpUserName))
            smtpClient.Credentials = new NetworkCredential(SmtpUserName, SmtpUserPassword);
        using(MailMessage message = report.ExportToMail("",
                ",,", "Enter_Message_Subject")) {

Email a Report in a Web Application

You can send a request to the server to export a report to PDF and email the resulting PDF document.

View Example: How to send a report via Email from the client side

Do the following:

Server Side
Client Side
  • Call the PerformCustomDocumentOperation method to pass email address to the DocumentOperationService on the server.
See Also