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:
Create an event handler for the button click:
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.