logo
small logo
  • Products
  • Buy
  • Support
  • Articles
  • Customer panel Support
    • en
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • How to send report in PDF to Email from application code
  • How to programmatically set the default email client settings for sending emails from FastReport.NET

    February 12, 2021

    Like many other report generators, FastReport .NET allows you to send a report via email

    read more
  • How to protect your PDF?

    November 30, 2020

    On the Data protection day, we decided to prepare an article about the PDF documents

    read more
  • Interactive forms in PDF export Fast Report .NET 2018

    January 17, 2018

    It's no secret that the PDF standard allows you to create fillable forms. That is,

    read more
  • How to insert a report into the body of a email

    July 9, 2020

    By default, FastReport.Net allows you to send e-mails with an attached report file in one

    read more
  • How to make PDF on Raspberry PI with .NET Core

    May 26, 2020

    Raspberry PI is a miniature single-board computer with ARM processor. This microcomputer is often used

    read more

How to send report in PDF to Email from application code

April 5, 2016

It is no secret that FastReport .Net allows you to send reports by email. But few people know how to do it by using the code in a custom application. In such way that you wouldn't have to run a report and send it via email manually. The required reports will be automatically sent to a specified e-mail address with help one button, or schedule.

Let's consider the example of sending the report in PDF format by e-mail.

Create WindowsForms application. Add buttons and two text fields. In the first one, we will input recipient's email address, and the second - mail server for outgoing mail.

We will need the following libraries:

1
2
3
using FastReport;
using FastReport.Export;
using FastReport.Utils;

Create an event handler for the button click:     

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 private void button1_Click(object sender, EventArgs e)
 {
 Config.ReportSettings.ShowProgress = false; //Disable progress window
 Report report1 = new Report(); //Create new report object
 report1.Load(Environment.CurrentDirectory+"\\text.frx"); //Load report
 report1.Prepare(); //Prepare report
 FastReport.Export.Pdf.PDFExport pdf = new FastReport.Export.Pdf.PDFExport(); //Cteate PDF export
 FastReport.Export.Email.EmailExport email = new FastReport.Export.Email.EmailExport(); //Create Email export
 
 //email mailer settings
 email.Account.Address = "gromozekaster@yandex.ru";
 email.Account.Name = "TestUser";
 email.Account.Host = textBox2.Text;
 email.Account.Port = 25;
 email.Account.UserName = "Gromozekaster";
 email.Account.Password = "Password";
 email.Account.MessageTemplate = "Test";
 email.Account.EnableSSL = true;
 
 //email addressee settings
 email.Address = textBox1.Text;
 email.Subject = "Test Report";
 email.MessageBody = "Test message";
 
 email.Export = pdf; //Set export type
 email.SendEmail(report1); //Send email
 }

First of all I disabled the progress window in the report settings, but you can skip this step. If you do not need it, just do not write this line of code. Then create an instance of a report object and load the report into it. Before the export you need to prepare a report (Prepare), in other words - build it. Since the title of the article contains “PDF”, let's create an object of export to PDF.  Likewise we create export to email.

Now we can customize the export settings in the Email. In the Account - the sender's settings. Basically it is the outgoing mail server settings.

Next - set the parameters of the recipient as well as the email address, subject line, message text and export to the desired file type. Here it should be noted that is not necessary to export to PDF, you need only to create an export object. Email export makes exports to the specified format.

If you do not specify Export parameter, then the report will be sent in the FPX format. This file is preview of the report. You can view, print or export the report, but can not edit it.

Finally, we will send a letter using Sendmail method. Be sure to pass the report object to this method.

Considered method will be useful for standard emails, for example, you can arrange to automatically broadcast daily reports to your chief email.

about product download buy
avatar
Dmitriy Fedyashov
Technical Writer
Fast Reports Team: Dmitriy Fedyashov - Technical Writer at Fast Reports
.NET FastReport PDF Email

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • Ticket system
  • FAQ
  • Tutorial Video
  • Forum
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Contact us

© 1998-2022 by Fast Reports Inc.

  • Privacy Policy