logo
small logo
  • Products
  • Buy
  • Support
  • Articles
  • Customer panel Support
    • en
    • ru
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • How to send report in PDF to Email from application code
  • How to connect to VistaDB

    November 15, 2019

    The Vista database will fall into the type of embedded databases. These databases differ from

    read more
  • How to disable printing reports and other items from the menu when viewing the report FastReport.Net

    February 29, 2020

    The main report viewing tool FastReport.Net is Viewer. This viewer has a rich toolkit for

    read more
  • Create a new report with code VB.Net

    September 17, 2020

    Speaking of the .Net framework, we usually imagine the #C programming language. Simply because the

    read more
  • How to use QR-codes in FastReport.Net

    February 15, 2017

    Nowadays “QR-codes” are gaining their popularity. Unlike conventional barcodes, “QR-codes” allow you to encode more

    read more
  • How to make wedding invitations from Excel

    August 25, 2017

    Do you have a celebration on the occasion of the wedding? Do you need to

    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
Head of QA
.NET FastReport

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
  • Our team
  • Contact us

© 1998-2021 by Fast Reports Inc.

  • Privacy Policy