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.

August 12, 2024

How to build and install the Postgres plugin in FastReport .NET

This article describes how to connect to the database using the FastReport .NET plugin for the report designer from Visual Studio via the NuGet server.
August 08, 2024

How to install FastReport .NET and its components on Windows

Step-by-step instructions for online and manual installation via the FastReport registration code.NET and its components in Windows.
July 26, 2024

Updating HTMLObject as a plugin for FastReport .NET

Detailed instructions for using the new HTMLObject plugin, which uses splitting DOM HTML into FastReport report objects.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314

© 1998-2024 Fast Reports Inc.