-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU Affero General Public License as
-* published by the Free Software Foundation, either version 3 of the
-* License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU Affero General Public License for more details.
-*
-* You should have received a copy of the GNU Affero General Public License
-* along with this program. If not, see .
-*/
-
-// The html we want to send.
-const HTML: &str = r#"
-
-
-
-
- Hello from Lettre!
-
-
-
-
Hello from Lettre!
- A mailer library for Rust
-
-
-"#;
-
-use lettre::{
- message::{header, MultiPart, SinglePart},
- transport::smtp::authentication::Credentials,
- AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor,
-};
-
-async fn email() {
- let email = Message::builder()
- .from("NoBody ".parse().unwrap())
- .reply_to("Yuin ".parse().unwrap())
- .to("Hei ".parse().unwrap())
- .subject("Happy new async year")
- .multipart(
- MultiPart::alternative() // This is composed of two parts.
- .singlepart(
- SinglePart::builder()
- .header(header::ContentType::TEXT_PLAIN)
- .body(String::from(
- "Hello from Lettre! A mailer library for Rust",
- )), // Every message should have a plain text fallback.
- )
- .singlepart(
- SinglePart::builder()
- .header(header::ContentType::TEXT_HTML)
- .body(String::from(HTML)),
- ),
- )
- .unwrap();
-
- let creds =
- Credentials::new("smtp_username".to_string(), "smtp_password".to_string());
-
- let mailer: AsyncSmtpTransport =
- AsyncSmtpTransport::::relay("smtp.gmail.com")
- .unwrap()
- .credentials(creds)
- .build();
-
- // Send the email
- match mailer.send(email).await {
- Ok(_) => println!("Email sent successfully!"),
- Err(e) => panic!("Could not send email: {:?}", e),
- }
-}
diff --git a/src/email/mod.rs b/src/email/mod.rs
new file mode 100644
index 00000000..ee59faed
--- /dev/null
+++ b/src/email/mod.rs
@@ -0,0 +1,18 @@
+/*
+* Copyright (C) 2021 Aravinth Manivannan
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+pub mod verification;
diff --git a/src/email/verification.rs b/src/email/verification.rs
new file mode 100644
index 00000000..3768156e
--- /dev/null
+++ b/src/email/verification.rs
@@ -0,0 +1,75 @@
+/*
+* Copyright (C) 2021 Aravinth Manivannan
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+//! Email operations: verification, notification, etc
+use lettre::{
+ message::{header, MultiPart, SinglePart},
+ AsyncTransport, Message,
+};
+
+use crate::AppData;
+use crate::SETTINGS;
+
+// The html we want to send.
+const HTML: &str = r#"
+
+
+
+
+ Hello from Lettre!
+
+
+
+
Hello from Lettre!
+ A mailer library for Rust
+
+
+"#;
+
+async fn verification(data: &AppData) {
+ if let Some(smtp) = SETTINGS.smtp.as_ref() {
+ let from = format!("mCaptcha Admin <{}>", smtp.from);
+ const SUBJECT: &str = "[mCaptcha] Please verify your email";
+
+ let email = Message::builder()
+ .from(from.parse().unwrap())
+ .reply_to("Yuin ".parse().unwrap())
+ .to("Hei ".parse().unwrap())
+ .subject(SUBJECT)
+ .multipart(
+ MultiPart::alternative() // This is composed of two parts.
+ .singlepart(
+ SinglePart::builder()
+ .header(header::ContentType::TEXT_PLAIN)
+ .body(String::from(
+ "Hello from Lettre! A mailer library for Rust",
+ )), // Every message should have a plain text fallback.
+ )
+ .singlepart(
+ SinglePart::builder()
+ .header(header::ContentType::TEXT_HTML)
+ .body(String::from(HTML)),
+ ),
+ )
+ .unwrap();
+
+ // unwrap is OK as SETTINGS.smtp is check at the start
+ match data.mailer.as_ref().unwrap().send(email).await {
+ Ok(_) => println!("Email sent successfully!"),
+ Err(e) => panic!("Could not send email: {:?}", e),
+ }
+ }
+}