Email Sending
Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher
This article covers how to send 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.
curl tool.
Any other REST client will work, but examples will be built for curl.
Active subscription to one of the following products: FastReport Cloud, FastReport Corporate Server, or FastReport Publisher.
Internet access.
Configured and accessible email account.
Note! The points above describe recommended tools.
Creating a Task
Let's look at creating an email template sending task:
// Creating a task
curl -X 'POST' \
'https://{host_name}/api/tasks/v1/Tasks' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"$t": "CreateEmailTaskVM",
"name": "Email sending task",
"subscriptionId": "{workspace id}",
"inputFile": {
"entityId": "{template id}",
"type": "Template"
},
"from": "{sender email}",
"to": ["{recipient email 1}", "{recipient email 2}"],
"subject": "Test message",
"EnableSsl": true,
"username": "{username}",
"password": "{password}",
"server": "{smtp server address}",
"port": 587
}'
// Running task by identifier
curl -X 'POST' \
'https://{host_name}/api/tasks/v1/Tasks/{task identifier}/run' \
-H 'accept: */*' \
-d ''
In the EntityId and SubscriptionId fields, you should enter real object identifiers. Otherwise, the task will be terminated with an error.
Executing Task from Request Body
curl -X 'POST' \
'https://{host_name}/api/tasks/v1/Tasks/run' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"$t": "RunEmailTaskVM",
"subscriptionId": "{workspace id}",
"inputFile": {
"content": "{template file in base64}",
"type": "Template"
},
"from": "{sender email}",
"to": ["{recipient email 1}", "{recipient email 2}"],
"subject": "Test message",
"EnableSsl": true,
"username": "{username}",
"password": "{password}",
"server": "{smtp server address}",
"port": 587
}'
Note! In this case, sending the file via email will be performed directly by this request and the task will not be saved in the database. Also, in the content field you can pass reports and ready documents in various formats, for example, PDF, XLSX, etc.
Note! The examples don't have the Authorization header because an authentication model based on cookies is used. For more details about authorization, read the section Authentication and Authorization