kannon_mail is the (unofficial) Rust client library for Kannon.
First, instantiate the Kannon client
let sender = Sender {
email: "sender@kannon.dev".into(),
alias: "Kannon".into(),
};
let mut kannon = Kannon::new(
"<YOUR DOMAIN>".into(),
"<YOUR KEY>".into(),
sender,
"<YOUR KANNON API HOST>".into(),
)
.await?;Note
Remember to add https:// to the API host (e.g. https://grpc.kannon.email:443)!
Also, the sender email should be part of your domain
To send mails, use the send_mail method:
let recipients = vec![Recipient {
email: "test@mail.com".into(),
fields: HashMap::from([("name".into(), "Test".into())]),
}];
kannon.send_email(
recipients,
"Hello from Kannon".into(), // Subject
"<body>Hello from Kannon, {{ name }}!!</body>".into(), // Html Body
vec![] // Attachments
)
.await?;Similar to mails, you can send templates by indicating the template id instead of the mail body:
kannon.send_template(
recipients,
"Hello from Kannon".into(),
"<template-id>".into(),
vec![]
)
.await?;Developed (together with @ludusrusso] during Open Source Saturday Milan.