Add code quality checks
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
2025-07-04 13:54:44 +02:00
parent 046ac8d2dc
commit 37d63a08f8
4 changed files with 76 additions and 3 deletions

39
.drone.yml Normal file
View File

@ -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: {}

4
README.md Normal file
View File

@ -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.

5
renovate.json Normal file
View File

@ -0,0 +1,5 @@
{
"extends": [
"local>renovate/presets"
]
}

View File

@ -1,8 +1,9 @@
use clap::Parser; use clap::Parser;
use lettre::message::header::ContentType;
use lettre::message::Mailbox; 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::transport::smtp::extension::ClientId;
use lettre::{Message, SmtpTransport, Transport};
/// Simple mail sender /// Simple mail sender
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@ -48,12 +49,20 @@ struct Args {
#[arg(long)] #[arg(long)]
smtp_port: Option<u16>, smtp_port: Option<u16>,
/// SMTP username
#[arg(long)]
smtp_username: Option<String>,
/// SMTP password
#[arg(long)]
smtp_password: Option<String>,
/// Disable TLS /// Disable TLS
#[arg(long)] #[arg(long)]
disable_tls: bool, disable_tls: bool,
/// Relay name /// Relay name
#[arg(long, default_value = "mail-out.mail.internal")] #[arg(long, default_value = "my-computer.com")]
smtp_relay_name: String, smtp_relay_name: String,
} }
@ -87,6 +96,11 @@ fn main() {
false => SmtpTransport::relay(&args.smtp_domain).unwrap(), false => SmtpTransport::relay(&args.smtp_domain).unwrap(),
}; };
mailer = mailer.hello_name(ClientId::Domain(args.smtp_relay_name)); 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 { if let Some(port) = args.smtp_port {
mailer = mailer.port(port); mailer = mailer.port(port);
} }
@ -103,3 +117,14 @@ fn main() {
Err(e) => panic!("Could not send email: {e:?}"), 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()
}
}