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

FastReport .Net is a full-featured report solution for Windows Forms, ASP.NET, MVC and .NET Core. It can be used in Microsoft Visual Studio 2005-2019. Support .Net Framework 2.0-4.x, .NET Core 3.0 and above.

In the new version of FastReport .NET 2021.1, we have implemented support for .NET 5. Added a new barcode-Deutsce Post Leitcode. The algorithm for converting RTF into report objects has been significantly improved. And also added a new function for converting numbers. Welcome to download and experience. (Click the button below to download)

Click to download the latest version of FastReport.NET v2021.1 now

Like many other report generators, FastReport.Net allows you to send reports via email in any available export format. You can send emails in report preview mode or custom application code.

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

On the "Account" tab, set the email client settings used to send emails and the sender's address and name.

Insert picture description here

On the "Email" tab, set the recipient's address, e-mail subject, e-mail text, and most importantly, the report format to be attached to the e-mail. After sending the email, the report will be automatically exported in the specified format and attached to the email.

Insert picture description here

Any settings you set will be saved as default settings when you send an email, and you can use them in the future. The same is true when initializing email settings values ​​in the application code of the EnvironmentSettings component. The settings are only saved after sending the email. But what if you want to apply the default email settings immediately without having to send an email to save them? This may be useful if you use the report generator in a multi-user application and want to make email presets so that the user only needs to enter the recipient's address and click the "Send" button.

The default email settings are located in the FastReport.Net report generator configuration file, which is usually located in 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 "Account Settings" section, and if you have sent mail from preview mode, you will see the default settings for sending mail. To edit this file in a custom application, use the following code:

XmlItem xi = Config.Root.FindItem("EmailExport").FindItem("AccountSettings");
// save account info
xi.SetProp("Address", "[email protected]");
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 mail settings section. Then-we set it up. If this part or its attributes are not in the configuration, they will be added automatically.
In this way, we can create pre-configured mail settings for users.

Guess you like

Origin blog.csdn.net/RoffeyYang/article/details/113862091