Send emails through mailgun in rust asynchronously
toml
mailgun_api = "0.2"
reqwest = {version = "0.10", features = ["json"]}
serde = { version = "1.0", features = ["derive"]}
serde_derive = "1.0"
serde_json = "1.0"
tokio = { version = "0.2", features = ["macros"]}
```rust use mailgunapi::MailgunApi; use mailgunapi::api::EmailParams; use dotenv::dotenv; use std::env;
// Inside of you tokio implementation dotenv().ok();
let mailgunsecret = env::var("MAILGUNSECRET").expect("MAILGUNSECRET must be set"); let mailgundomain = env::var("MAILGUNDOMAIN").expect("MAILGUNDOMAIN must be set"); let mailgunendpoint = env::var("MAILGUNENDPOINT").expect("MAILGUNENDPOINT must be set"); let sender = env::var("EMAILFROM").expect("MAILFROM must be set"); let receiver = env::var("EMAILRECEIVERTEST").expect("EMAILRECEIVER_TEST must be set");
let params = EmailParams { from: sender, to: receiver, subject: "test mailgung api".tostring(), text: Some("hello this is a test".tostring()), html: None, };
let mut mailgun = MailgunApi::new(&mailgunsecret, &mailgunendpoint, &mailgun_domain);
let response = mailgun.send_email::
asserteq!(response.isok(), true) ```
MAILGUN_DOMAIN=[YOUR DOMAIN]
MAILGUN_SECRET=[YOUR MAILGUN API SECRET]
MAILGUN_ENDPOINT=[MAILGUN ENDPOINT] // There is two endpoint currently: api.mailgun.net and api.eu.mailgun.net
EMAIL_RECEIVER_TEST=[EMAIL RECEIVER TEST]
EMAIL_FROM=[SENDER TEST]
cargo test
Warning: when you are running the tests you are sending a email to the receiver that you set
The dtos are structures used to transform the json retrieved from Mailung API in data accesible by the rust aplication.
It wasn't possible to see any Mailgun documentation which specify which parameters are nullable then maybe is possible
to get an error in the response because the Dto property is not typed as Option
(please open an issue if that happens),
for this reason the methods accept Generics which you need to pass the Dtos provided or yours
If you like Mailgun API, help us supporting the project: - Github Sponsors - Paypal
Mailgun API is MIT licensed