summaryrefslogtreecommitdiffstats
path: root/tools/src/smtp_conn.rs
blob: 0d87dd0db0202396c66fa6018b392f4dff44e782 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
extern crate melib;

use melib::futures;
use melib::smol;
use melib::smtp::*;
use melib::Result;

fn main() -> Result<()> {
    let conf = SmtpServerConf {
        hostname: "smtp1.example.com".into(),
        port: 587,
        security: SmtpSecurity::StartTLS {
            danger_accept_invalid_certs: false,
        },
        extensions: SmtpExtensionSupport::default(),
        auth: SmtpAuth::Auto {
            username: "username".into(),
            password: Password::CommandEval("gpg2 --no-tty -q -d ~/.passwords/password.gpg".into()),
            require_auth: true,
        },
        envelope_from: String::new(),
    };
    std::thread::spawn(move || {
        let ex = smol::Executor::new();
        futures::executor::block_on(ex.run(futures::future::pending::<()>()));
    });

    let mut conn = futures::executor::block_on(SmtpConnection::new_connection(conf)).unwrap();
    futures::executor::block_on(conn.mail_transaction(
         r##"To: username@example.com
Auto-Submitted: auto-generated
Subject: Fwd: *** SMTP TEST #2 information ***
From: Xxxxx <username@example.com>
Message-Id: <E1hSjnr-0003fN-RL2@example>
Date: Mon, 13 Jul 2020 15:02:15 +0300

machine : May 20 18:02:00 : user : user NOT in sudoers ; TTY=pts/13 ; PWD=/tmp/db-project ; USER=postgres ; COMMAND=/usr/bin/dropdb Prescriptions-R-X"##,
None
    )).unwrap();
    Ok(())
}