-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webserver): Create template system for emails (#1447)
* feat(webserver): Create template system for emails * Put newlines between lines of email body * Move email template folder
- Loading branch information
Showing
3 changed files
with
34 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
You've been invited to join a Tabby workspace! | ||
Welcome to Tabby! You have been invited to join a Tabby Server, where you can tap into AI-driven code completions and chat assistants. | ||
|
||
Go to {external_url}/auth/signup?invitationCode={code} to join! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
pub struct EmailContents { | ||
pub subject: String, | ||
pub body: String, | ||
} | ||
|
||
fn format_email(template: &'static str, replacements: &[(&str, &str)]) -> EmailContents { | ||
let mut lines = template.lines(); | ||
let mut subject = lines | ||
.next() | ||
.expect("Email must have subject line") | ||
.to_string(); | ||
let body: Vec<&str> = lines.collect(); | ||
let mut body = body.join("\n"); | ||
for (name, replacement) in replacements { | ||
body = body.replace(name, replacement); | ||
subject = subject.replace(name, replacement); | ||
} | ||
EmailContents { subject, body } | ||
} | ||
|
||
pub fn invitation_email(external_url: &str, code: &str) -> EmailContents { | ||
format_email( | ||
include_str!("../../../email_templates/invitation.html"), | ||
&[("{external_url}", external_url), ("{code}", code)], | ||
) | ||
} |