How to programmatically set the default email client settings for sending emails from FastReport.NET

2021-02-12

Like many other report generators, FastReport .NET allows you to send a report via email in any of the available export formats. You can send an e-mail either in the report preview mode or in the custom application code.

To send an email you need to set the sender, recipient settings.

On the Account tab, you set the email client settings for sending emails and the sender's address and name.

FastReport.NET

On the Email tab you set up the recipient's address, email subject, email text, and most importantly the report format to be attached to the email. When the email is sent, the report will be automatically exported in the specified format and attached to the email. 

FastReport.NET

Any settings you set will be saved as the default settings when you send the email, and you can use them in the future. The same is true when you initialize the email settings values in the application code in the EnvironmentSettings component. The settings will only be saved once the email has been sent. But what if you want the default email settings to be applied immediately, without having to send an email to save them? This might be useful if you are using the report generator in a multi-user application and want to make mail presets so that users only have to enter the recipient address and click the send button.

The default email settings are located in the FastReport .NET report generator configuration file, which is usually located at the specified path 

C:\Users\User\AppData\Local\FastReport\FastReport.config.

Open this file in a text editor and you will see an XML. Find the AccountSettings section and, if you have already sent mail from preview mode, you will see the default settings for sending mail. To edit this file in your custom application use the following code:

XmlItem xi = Config.Root.FindItem("EmailExport").FindItem("AccountSettings");
// save account info
xi.SetProp("Address", "a@a.com");
xi.SetProp("Name", "Name");
xi.SetProp("Template", "template");
xi.SetProp("Host", "host");
xi.SetProp("Port", "25");
xi.SetProp("UserName", "UserName");
xi.SetProp("Password", "Password");
xi.SetProp("EnableSSL", "1"); // "0" if SSL needs to be disabled

In this code, we read the configuration file and found the section for the mailing settings. And then - we set the settings. If this section or its properties are not in the configuration, they will be added automatically.

This way we can create pre-configured mail settings for our users.

.NET FastReport Email .NET FastReport Email
February 20, 2025

Using Dot Matrix Printers for Printing Receipts

This article will explore how to integrate a dot matrix printer into the process of creating and outputting reports using FastReport .NET.
February 17, 2025

Adding New Users to FastReport Cloud

In the Business edition of the FastReport Cloud service, you can add users to a single workspace for simultaneous collaboration.
February 10, 2025

How to Try FastReport .NET WEB Before Purchase

By testing the WEB pack before purchasing, you can make an informed choice about whether FastReport is suitable for you.NET for your tasks.
Fast Reports
  • 800-985-8986 (English, US)
  • +31 97 01025-8466 (English, EU)
  • +49 30 56837-3928 (German, DE)
  • +55 19 98147-8148 (Portuguese, BR)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2025 Fast Reports Inc.