diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..f46734a --- /dev/null +++ b/.drone.yml @@ -0,0 +1,39 @@ +--- +kind: pipeline +type: docker +name: default + +steps: + - name: fetch_dependencies + image: rust + volumes: + - name: rust_registry + path: /usr/local/cargo/registry + commands: + - cargo fetch + + - name: code_quality + image: rust + volumes: + - name: rust_registry + path: /usr/local/cargo/registry + depends_on: + - fetch_dependencies + commands: + - rustup component add clippy + - cargo clippy -- -D warnings + + - name: test + image: rust + volumes: + - name: rust_registry + path: /usr/local/cargo/registry + depends_on: + - code_quality + commands: + - cargo test + +volumes: + - name: rust_registry + temp: {} + diff --git a/README.md b/README.md new file mode 100644 index 0000000..618090e --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# MailSender +Basic command line tool that can be used to send email, using the SMTP protocol. + +This tool has been written in Rust, using the `lettre` crate. \ No newline at end of file diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..df1d496 --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "local>renovate/presets" + ] +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 0514e5d..f96ddb3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,9 @@ use clap::Parser; -use lettre::message::header::ContentType; use lettre::message::Mailbox; -use lettre::{Message, SmtpTransport, Transport}; +use lettre::message::header::ContentType; +use lettre::transport::smtp::authentication::Credentials; use lettre::transport::smtp::extension::ClientId; +use lettre::{Message, SmtpTransport, Transport}; /// Simple mail sender #[derive(Parser, Debug)] @@ -48,12 +49,20 @@ struct Args { #[arg(long)] smtp_port: Option, + /// SMTP username + #[arg(long)] + smtp_username: Option, + + /// SMTP password + #[arg(long)] + smtp_password: Option, + /// Disable TLS #[arg(long)] disable_tls: bool, /// Relay name - #[arg(long, default_value = "mail-out.mail.internal")] + #[arg(long, default_value = "my-computer.com")] smtp_relay_name: String, } @@ -87,6 +96,11 @@ fn main() { false => SmtpTransport::relay(&args.smtp_domain).unwrap(), }; mailer = mailer.hello_name(ClientId::Domain(args.smtp_relay_name)); + + if let (Some(username), Some(password)) = (args.smtp_username, args.smtp_password) { + mailer = mailer.credentials(Credentials::new(username, password)); + } + if let Some(port) = args.smtp_port { mailer = mailer.port(port); } @@ -103,3 +117,14 @@ fn main() { Err(e) => panic!("Could not send email: {e:?}"), } } + + +#[cfg(test)] +mod test { + use crate::Args; + #[test] + fn verify_cli() { + use clap::CommandFactory; + Args::command().debug_assert() + } +} \ No newline at end of file