Symfony build REST API for asynchronous email handling following the coding challenge
Write REST API that:
-
Accepts following parameters
-
key – name of mail template
-
subject – email subject
-
id – identificator of order
-
date – in format of YYYY-MM-DD
-
link – formatted link object (label and url)
-
email – target email address
-
bcc – hidden copy email address
-
delayed_send – false or date time
-
-
Logs incoming request (either DB or log)
-
Adds request to queue or sends immediately
-
Fills predetermined email template with data above
-
Sends Mail to address and bcc to second email address
-
Responds with status code (200/202)
Example of input data
{
["key": "expiration", "delayed_send": "2022-12-22", "email": "jan.samek2@icewarp.com"
],
["bcc": "jan.samek2@icewarp.com"
],
"body_data": {
"id": "ABC-2022-XGF",
"date": "2022-12-24",
"link": {
"label": "icewarp.com", "url": "Go to our site"
}
}
}
Example of mail html:
EmailController handles /api/v1/send-email and validates POST requests using APIRequest.php validator If successful, it proceeds on storing the email in the DB and returns 202 accepted messages.
In the background, a cronjob is calling MailerDispatchCommand.php that checks for any unsent messages and builds an email with the twig template, and attempts to send it. In case of an exception, it is logged in var/log.
