mirror of
https://git.verdigado.com/NB-Public/simple-wkd.git
synced 2024-10-30 05:05:52 +01:00
Improve email formatting
This commit is contained in:
parent
82a7e4539b
commit
f4cec274bf
2 changed files with 41 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
|
use lettre::message::header::ContentType;
|
||||||
use log::{debug, error, trace, warn};
|
use log::{debug, error, trace, warn};
|
||||||
|
|
||||||
use crate::errors::Error;
|
use crate::errors::Error;
|
||||||
|
@ -103,6 +104,7 @@ pub fn confirm_action(token: &str) -> Result<(Action, String), Error> {
|
||||||
|
|
||||||
pub fn send_confirmation_email(address: &str, action: &Action, token: &str) -> Result<(), Error> {
|
pub fn send_confirmation_email(address: &str, action: &Action, token: &str) -> Result<(), Error> {
|
||||||
debug!("Sending email to {}", address);
|
debug!("Sending email to {}", address);
|
||||||
|
let template = fs::read_to_string(Path::new("static").join("mail-template.html")).unwrap();
|
||||||
let email = Message::builder()
|
let email = Message::builder()
|
||||||
.from(match SETTINGS.mail_settings.mail_from.parse() {
|
.from(match SETTINGS.mail_settings.mail_from.parse() {
|
||||||
Ok(mailbox) => mailbox,
|
Ok(mailbox) => mailbox,
|
||||||
|
@ -124,17 +126,23 @@ pub fn send_confirmation_email(address: &str, action: &Action, token: &str) -> R
|
||||||
.mail_subject
|
.mail_subject
|
||||||
.replace("%a", &action.to_string().to_lowercase()),
|
.replace("%a", &action.to_string().to_lowercase()),
|
||||||
)
|
)
|
||||||
.body(format!(
|
.header(ContentType::TEXT_HTML)
|
||||||
"{}",
|
.body(
|
||||||
SETTINGS
|
template
|
||||||
.external_url
|
.replace(
|
||||||
.join("api/")
|
"{{%u}}",
|
||||||
.unwrap()
|
SETTINGS
|
||||||
.join("confirm/")
|
.external_url
|
||||||
.unwrap()
|
.join("api/")
|
||||||
.join(token)
|
.unwrap()
|
||||||
.unwrap()
|
.join("confirm/")
|
||||||
));
|
.unwrap()
|
||||||
|
.join(token)
|
||||||
|
.unwrap()
|
||||||
|
.as_ref(),
|
||||||
|
)
|
||||||
|
.replace("{{%a}}", &action.to_string().to_lowercase()),
|
||||||
|
);
|
||||||
|
|
||||||
let message = match email {
|
let message = match email {
|
||||||
Ok(message) => message,
|
Ok(message) => message,
|
||||||
|
|
22
static/mail-template.html
Normal file
22
static/mail-template.html
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div style="width: 100%; text-align: center; display: flex; flex-direction: column;">
|
||||||
|
<p style="font-weight: bold; font-size: large;">Please open the following link in order to {{%a}} your key</p>
|
||||||
|
<div style="margin-top: 2rem; margin-bottom: 2rem;">
|
||||||
|
<a style="font-size: x-large; font-weight: bold;" ; href="{{%u}}">CONFIRM ACTION</a>
|
||||||
|
<p style="font-size: small;">{{%u}}</p>
|
||||||
|
</div>
|
||||||
|
<p style="font-size: small;">If you didn't request to {{%a}} a key, you can safely ignore this email.</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in a new issue