pub fn send_email(
    email_to: String,
    email_subject: String,
    email_html: String,
    email_text: String
) -> Result<lettre::smtp::response::Response> {
    let email_address = std::env::var("EMAIL_ADDRESS")
        .expect("EMAIL_ADDRESS must exist");    
    let email_password = std::env::var("EMAIL_APP_PASSWORD")
        .expect("EMAIL_APP_PASSWORD must exist");

    let email = match EmailBuilder::new()
        .from((email_address.clone(), "GreenPoll"))
        .to(email_to)
        .subject(email_subject)
        .alternative(email_html, email_text)
        .build() {
            Ok(val) => Ok(val),
            Err(e) => Err(Error::new(ErrorKind::Other, format!("Failed to build email: {}", e)))
        }?;

    let creds = Credentials::new(email_address.clone(), email_password.clone());

    let mut mailer = match SmtpClient::new_simple("smtp.gmail.com") {
        Ok(val) => Ok(val),
        Err(e) => Err(Error::new(ErrorKind::Other, format!("Failed to create email client: {}", e)))
    }?
        .credentials(creds)
        .transport();

    let result = match mailer.send(email.into()) {
        Ok(val) => Ok(val),
        Err(e) => Err(Error::new(ErrorKind::Other, format!("Failed to send email: {}", e)))
    }?;

    Ok(result)
}
/// Sends an email using the app email account
/// 
/// # Arguments
/// 
/// * `email_to` - The address to send the email to
/// * `email_subject` - The subject line of the email
/// * `email_html` - The HTML content to send in the email body
/// * `email_text` - The text content to send in the email body
Sends an email using the app email account
Sends an email using the app email account
pub fn send_email(
    email_to: String,
    email_subject: String,
    email_html: String,
    email_text: String
) -> Result<lettre::smtp::response::Response> {
    let email_address = std::env::var("EMAIL_ADDRESS")
        .expect("EMAIL_ADDRESS must exist");    
    let email_password = std::env::var("EMAIL_APP_PASSWORD")
        .expect("EMAIL_APP_PASSWORD must exist");
    let email = match EmailBuilder::new()
        .from((email_address.clone(), "GreenPoll"))
        .to(email_to)
        .subject(email_subject)
        .alternative(email_html, email_text)
        .build() {
            Ok(val) => Ok(val),
            Err(e) => Err(Error::new(ErrorKind::Other, format!("Failed to build email: {}", e)))
        }?;
    let creds = Credentials::new(email_address.clone(), email_password.clone());
    let mut mailer = match SmtpClient::new_simple("smtp.gmail.com") {
        Ok(val) => Ok(val),
        Err(e) => Err(Error::new(ErrorKind::Other, format!("Failed to create email client: {}", e)))
    }?
        .credentials(creds)
        .transport();
    let result = match mailer.send(email.into()) {
        Ok(val) => Ok(val),
        Err(e) => Err(Error::new(ErrorKind::Other, format!("Failed to send email: {}", e)))
    }?;
    Ok(result)
}
pub fn send_email ( email_to : String , email_subject : String , email_html : String , email_text : String ) -> Result < lettre :: smtp :: response :: Response > { let email_address = std :: env :: var ( " " ) . expect ( " " ) ; let email_password = std :: env :: var ( " " ) . expect ( " " ) ; let email = match EmailBuilder :: new ( ) . from ( ( email_address . clone ( ) , " " ) ) . to ( email_to ) . subject ( email_subject ) . alternative ( email_html , email_text ) . build ( ) { Ok ( val ) => Ok ( val ) , Err ( e ) => Err ( Error :: new ( ErrorKind :: Other , format ! ( " " e ) ) ) } ? ; let creds = Credentials :: new ( email_address . clone ( ) , email_password . clone ( ) ) ; let mut mailer = match SmtpClient :: new_simple ( " " ) { Ok ( val ) => Ok ( val ) , Err ( e ) => Err ( Error :: new ( ErrorKind :: Other , format ! ( " " e ) ) ) } ? . credentials ( creds ) . transport ( ) ; let result = match mailer . send ( email . into ( ) ) { Ok ( val ) => Ok ( val ) , Err ( e ) => Err ( Error :: new ( ErrorKind :: Other , format ! ( " " e ) ) ) } ? ; Ok ( result ) }
Sends an email using the app email account
Sends an email using the app email account
email_to
String
email_subject
String
email_html
String
email_text
String
email_to
String
email_subject
String
email_html
String
email_text
String