2.9 KiB
2.9 KiB
SMTPMail-drogon
Simple Mail for the Drogon framework.
It is made as a plugin for the drogon framework. It can be included into the drogon build with little modification of the class declaration.
Updates
- [ 13-06-2022 ] Fixed vulnerability issues reported by Sam.
- [ 13-09-2021 ] Added HTML content support.
- [ 23-12-2020 ] Added DNS support.
Acknowledgement
- The implementation takes SMTPClient for Qt from kelvins as reference.
- There requires a delay SSL encryption from the Tcp-socket (named TcpClient in trantor/drogon) and the major author of drogon reponsed quickly.
Usage
Download to the plugin directory of the target drogon app, E.g. ~/drogon-app/plugins
$ git clone https://github.com/ihmc3jn09hk/SMTPMail-drogon.git
$ cp SMTPMail-drogon/SMTPMail.* ~/drogon-app/plugins
- Be aware of add the plugin into the config.json. Set the "name" field to "SMTPMail"
Add the reference header and get the plugin from the app(), E.g.
...
#include "../plugins/SMTPMail.h"
...
//Inside some function, E.g. A controller function.
...
//Send an email
auto *smtpmailPtr = app().getPlugin<SMTPMail>();
auto id = smtpmailPtr->sendEmail(
"127.0.0.1", //The server IP/DNS
587, //The port
"mailer@something.com", //Who send the email
"receiver@otherthing.com", //Send to whom
"Testing SMTPMail Function", //Email Subject/Title
"Hello from drogon plugin", //Content
"mailer@something.com", //Login user
"123456", //User password
false //Is HTML content
);
...
//Or get noted when email is sent
...
void callback(const std::string &msg)
{
LOG_INFO << msg; /*Output e.g. "EMail sent. ID : 96ESERVDDFH17588ECF0C7B00326E3"*/
/*Do whatever you like*/
}
...
auto *smtpmailPtr = app().getPlugin<SMTPMail>();
auto id = smtpmailPtr->sendEmail(
"127.0.0.1", //The server IP/DNS
587, //The port
"mailer@something.com", //Who send the email
"receiver@otherthing.com", //Send to whom
"Testing SMTPMail Function", //Email Subject/Title
"Hello from drogon plugin", //Content
"mailer@something.com", //Login user
"123456", //User password
false, //Is HTML content
callback //Callback
);
$ cd ~/drogon-app/build
$ make
Licence
- Feel free to use, thanks to open-source.
- For the sake of concern on commercial usage, a simple licence is included in each of the files.