Unsubscribe link in emails sent
Some checks failed
Rust / Test (push) Has been cancelled
Rust / Rustfmt (push) Has been cancelled
Rust / Clippy (push) Has been cancelled
Rust / Code coverage (push) Has been cancelled

This commit is contained in:
Alphonse Paix
2025-09-22 01:25:36 +02:00
parent 7af07ea0dd
commit 72fa283a6d
13 changed files with 431 additions and 211 deletions

View File

@@ -63,8 +63,25 @@ pub struct NewPostEmailTemplate<'a> {
pub post_excerpt: &'a str,
}
impl<'a> NewPostEmailTemplate<'a> {
pub fn text_version(&self) -> String {
#[derive(Template)]
#[template(path = "../templates/email/standalone.html")]
pub struct StandaloneEmailTemplate<'a> {
pub base_url: &'a str,
pub html_content: &'a str,
pub text_content: &'a str,
}
pub trait EmailTemplate: Sync {
fn html(&self) -> String;
fn text(&self) -> String;
}
impl<'a> EmailTemplate for NewPostEmailTemplate<'a> {
fn html(&self) -> String {
self.render().unwrap()
}
fn text(&self) -> String {
format!(
r#"New post available!
@@ -86,10 +103,31 @@ Alphonse
zero2prod - Building better backends with Rust
Visit the blog: {}
Unsubscribe: {}/unsubscribe
Unsubscribe: {}/unsubscribe?token=UNSUBSCRIBE_TOKEN
You're receiving this because you subscribed to the zero2prod newsletter."#,
self.post_title, self.base_url, self.post_id, self.base_url, self.base_url,
)
}
}
impl<'a> EmailTemplate for StandaloneEmailTemplate<'a> {
fn html(&self) -> String {
self.render().unwrap()
}
fn text(&self) -> String {
format!(
r#"{}
---
zero2prod - Building better backends with Rust
Visit the blog: {}
Unsubscribe: {}/unsubscribe?token=UNSUBSCRIBE_TOKEN
You're receiving this because you subscribed to the zero2prod newsletter."#,
self.text_content, self.base_url, self.base_url
)
}
}