mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 05:26:59 +00:00
Removed email.rs and cleaned up.
This commit is contained in:
75
src/email.rs
75
src/email.rs
@@ -1,75 +0,0 @@
|
||||
/*use lettre::smtp::authentication::{ Credentials, Mechanism };
|
||||
use lettre::{ SmtpClient, SmtpTransport, Transport, SendableEmail, Envelope, EmailAddress, SendmailTransport };
|
||||
use lettre_email::EmailBuilder;
|
||||
use lettre::smtp::extension::ClientId;
|
||||
use lettre::smtp::ConnectionReuseParameters;
|
||||
|
||||
use std::env;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use once_cell::sync::OnceCell;
|
||||
static mut MAILER: OnceCell<Mutex<SmtpTransport>> = OnceCell::new();
|
||||
|
||||
pub fn connect() {
|
||||
let host = env::var("SMTP_HOST").expect("SMTP_HOST not in environment variables!");
|
||||
let port: u32 = env::var("SMTP_PORT").expect("SMTP_PORT not in environment variables!").parse().unwrap();
|
||||
let domain = env::var("SMTP_DOMAIN").expect("SMTP_DOMAIN not in environment variables!");
|
||||
let username = env::var("SMTP_USERNAME").expect("SMTP_USERNAME not in environment variables!");
|
||||
|
||||
let mailer = SmtpClient::new_simple(&host).unwrap()
|
||||
.hello_name(ClientId::Domain(domain))
|
||||
.credentials(Credentials::new(username, env::var("SMTP_PASSWORD").expect("SMTP_PASSWORD not in environment variables!")))
|
||||
.smtp_utf8(true)
|
||||
.authentication_mechanism(Mechanism::Plain)
|
||||
.connection_reuse(ConnectionReuseParameters::ReuseUnlimited).transport();
|
||||
|
||||
unsafe {
|
||||
if let Err(_) = MAILER.set(Mutex::new(mailer)) {
|
||||
panic!("Failed to set global mailer!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send(recipient: String, title: String, contents: String) {
|
||||
let username = env::var("SMTP_USERNAME").expect("SMTP_USERNAME not in environment variables!");
|
||||
let email = EmailBuilder::new()
|
||||
.to(recipient)
|
||||
.from(username)
|
||||
.subject(title)
|
||||
.text(contents)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let email = SendableEmail::new(
|
||||
Envelope::new(
|
||||
Some(EmailAddress::new(username).unwrap()),
|
||||
vec![EmailAddress::new(recipient).unwrap()],
|
||||
)
|
||||
.unwrap(),
|
||||
title,
|
||||
contents.into_bytes(),
|
||||
);
|
||||
|
||||
let mut sender = SendmailTransport::new();
|
||||
let result = sender.send(email);
|
||||
|
||||
unsafe {
|
||||
MAILER.get_mut().unwrap().lock().unwrap().send(email).expect("Failed to send email!");
|
||||
}
|
||||
}*/
|
||||
|
||||
pub fn connect() {
|
||||
//
|
||||
}
|
||||
|
||||
use sendmail;
|
||||
use std::env;
|
||||
|
||||
pub fn send(recipient: &str, title: &str, contents: &str) {
|
||||
sendmail::email::send(
|
||||
&env::var("SMTP_USERNAME").expect("SMTP_USERNAME not in environment variables!"),
|
||||
&vec![ recipient ][..],
|
||||
title,
|
||||
contents
|
||||
).unwrap();
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
pub mod database;
|
||||
pub mod routes;
|
||||
pub mod email;
|
||||
pub mod auth;
|
||||
|
||||
use dotenv;
|
||||
@@ -12,8 +11,6 @@ use dotenv;
|
||||
fn main() {
|
||||
dotenv::dotenv().ok();
|
||||
database::connect();
|
||||
email::connect();
|
||||
email::send("me@insrt.uk", "test", "test email");
|
||||
|
||||
//routes::mount(rocket::ignite()).launch();
|
||||
routes::mount(rocket::ignite()).launch();
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
use crate::database;
|
||||
use bson::{ bson, doc, ordered::OrderedDocument };
|
||||
|
||||
#[get("/")]
|
||||
pub fn root() -> String {
|
||||
let client = database::get_connection();
|
||||
let cursor = client.database("revolt").collection("users").find(None, None).unwrap();
|
||||
|
||||
let results: Vec<Result<OrderedDocument, mongodb::error::Error>> = cursor.collect();
|
||||
|
||||
format!("ok boomer, users: {}", results.len())
|
||||
}
|
||||
|
||||
#[get("/reg")]
|
||||
pub fn reg() -> String {
|
||||
let client = database::get_connection();
|
||||
let col = client.database("revolt").collection("users");
|
||||
|
||||
col.insert_one(doc! { "username": "test" }, None).unwrap();
|
||||
|
||||
format!("inserted")
|
||||
}
|
||||
Reference in New Issue
Block a user