Sending via Email
Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher
In this article, we will consider the method of sending a report via email. Instructions on how to work with tasks are described in the General Information section.
Getting Started
You will need the following tools and capabilities:
Knowledge of using API key in Service solutions.
This article will skip additional information on authentication and authorization.
C# code editor or text editor, such as Visual Studio Code.
Report template.
It can be prepared using the free FastReport Community Designer program.
Active subscription to one of the following products: FastReport Cloud, FastReport Corporate Server, or FastReport Publisher.
Internet access.
Configured and accessible mail server.
Note! This guide assumes that you already know how to develop your application in the C# programming language.
Note! The points above describe the recommended tools.
Note! This guide assumes that you have experience configuring mail server connections.
Creating a Task
Let's consider creating an email template sending task:
// Object initialization
CreateEmailTaskVM emailTaskVM = new CreateEmailTaskVM
{
Name = "Email Sending Task",
SubscriptionId = "{workspace identifier}",
InputFile = new InputFileVM
{
EntityId = "{template identifier}",
Type = FileKind.Template
},
From = "admin@company.com",
To = ["user@company.com", "seller@company.com"],
Subject = "Important Report",
Body = "An important report is attached to this email.",
EnableSsl = true,
Username = "admin@company.com",
Password = "parol123",
Server = "smtp.company.com",
Port = 587
};
// Creating a task
TaskBaseVM emailTask = await tasksClient.CreateTaskAsync(emailTaskVM);
// Run task by identifier
await tasksClient.RunTaskByIdAsync(emailTask.Id);
Real object identifiers should be entered in the EntityId and SubscriptionId fields. Otherwise, the task will be aborted with an error.
Executing Task from Request Body
RunEmailTaskVM emailTaskVM = new RunEmailTaskVM
{
SubscriptionId = "{workspace identifier}",
InputFile = new RunInputFileVM
{
EntityId = "{template identifier}",
Type = FileKind.Template
},
From = "admin@company.com",
To = ["user@company.com", "seller@company.com"],
Subject = "Important Report",
Body = "An important report is attached to this email.",
EnableSsl = true,
Username = "admin@company.com",
Password = "parol123",
Server = "smtp.company.com",
Port = 587
};
// Task execution
TaskMessageIdVM emailTask = await tasksClient.RunTaskAsync(emailTaskVM);
Note! In this case, the file sending via email will be performed directly by this request and the task will not be saved in the database. Also, you can pass reports and ready documents in various formats in the content field, for example, PDF, XLSX, etc.
Note! The message identifier will be returned in emailTask.