Crates.io | mailgun-rs |
lib.rs | mailgun-rs |
version | 0.1.12 |
source | src |
created_at | 2019-09-09 12:23:46.385148 |
updated_at | 2024-10-11 11:49:50.689178 |
description | An unofficial client library for the Mailgun API |
homepage | |
repository | https://github.com/dongri/mailgun-rs |
max_upload_size | |
id | 163500 |
size | 39,738 |
An unofficial client library for the Mailgun API
# Cargo.toml
[dependencies]
mailgun-rs = "0.1.12"
See examples/async
$ cd examples/async
$ cargo run
use mailgun_rs::{EmailAddress, Mailgun, MailgunRegion, Message};
use std::collections::HashMap;
fn main() {
let domain = "huatuo.xyz";
let key = "key-xxxxxx";
let recipient = "dongrium@gmail.com";
send_html(recipient, key, domain);
send_template(recipient, key, domain);
}
fn send_html(recipient: &str, key: &str, domain: &str) {
let recipient = EmailAddress::address(recipient);
let message = Message {
to: vec![recipient],
subject: String::from("mailgun-rs"),
html: String::from("<h1>hello from mailgun</h1>"),
..Default::default()
};
let client = Mailgun {
api_key: String::from(key),
domain: String::from(domain),
message,
};
let sender = EmailAddress::name_address("no-reply", "no-reply@hackerth.com");
match client.send(MailgunRegion::US, &sender) {
Ok(_) => {
println!("successful");
}
Err(err) => {
println!("Error: {err}");
}
}
}
fn send_template(recipient: &str, key: &str, domain: &str) {
let mut template_vars = HashMap::new();
template_vars.insert(String::from("firstname"), String::from("Dongri"));
let recipient = EmailAddress::address(recipient);
let message = Message {
to: vec![recipient],
subject: String::from("mailgun-rs"),
template: String::from("template-1"),
template_vars,
..Default::default()
};
let client = Mailgun {
api_key: String::from(key),
domain: String::from(domain),
message,
};
let sender = EmailAddress::name_address("no-reply", "no-reply@hackerth.com");
match client.send(MailgunRegion::US, &sender) {
Ok(_) => {
println!("successful");
}
Err(err) => {
println!("Error: {err}");
}
}
}