Skip to content

Commit

Permalink
fix test-smtp api
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bonez committed Jan 14, 2025
1 parent fec8d5b commit 668a0b8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/startos/src/bins/registry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ffi::OsString;

use clap::Parser;
use futures::{FutureExt};
use futures::FutureExt;
use tokio::signal::unix::signal;
use tracing::instrument;

Expand Down
4 changes: 2 additions & 2 deletions core/startos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ pub fn server<C: Context>() -> ParentHandler<C> {
)
.subcommand(
"test-smtp",
from_fn_async(system::test_system_smtp)
from_fn_async(system::test_smtp)
.no_display()
.with_about("Send test email using system smtp server and credentials")
.with_about("Send test email using provided smtp server and credentials")
.with_call_remote::<CliContext>()
)
.subcommand(
Expand Down
38 changes: 32 additions & 6 deletions core/startos/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,15 +878,33 @@ pub async fn clear_system_smtp(ctx: RpcContext) -> Result<(), Error> {
}
Ok(())
}
pub async fn test_system_smtp(
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Parser, TS)]
#[ts(export)]
#[serde(rename_all = "camelCase")]
pub struct TestSmtpParams {
#[arg(long)]
pub server: String,
#[arg(long)]
pub port: u16,
#[arg(long)]
pub from: String,
#[arg(long)]
pub to: String,
#[arg(long)]
pub login: String,
#[arg(long)]
pub password: Option<String>,
}
pub async fn test_smtp(
_: RpcContext,
SmtpValue {
TestSmtpParams {
server,
port,
from,
to,
login,
password,
}: SmtpValue,
}: TestSmtpParams,
) -> Result<(), Error> {
use rustls_pki_types::pem::PemObject;

Expand All @@ -913,17 +931,25 @@ pub async fn test_system_smtp(
);
let client = SmtpClientBuilder::new_with_tls_config(server, port, cfg)
.implicit_tls(false)
.credentials((login.clone().split_once("@").unwrap().0.to_owned(), pass_val));
.credentials((
login.clone().split_once("@").unwrap().0.to_owned(),
pass_val,
));

let message = MessageBuilder::new()
.from((from.clone(), login.clone()))
.to(vec![(from, login)])
.to(to)
.subject("StartOS Test Email")
.text_body("This is a test email sent from your StartOS Server");
client
.connect()
.await
.map_err(|e| Error::new(eyre!("mail-send connection error: {:?}", e), ErrorKind::Unknown))?
.map_err(|e| {
Error::new(
eyre!("mail-send connection error: {:?}", e),
ErrorKind::Unknown,
)
})?
.send(message)
.await
.map_err(|e| Error::new(eyre!("mail-send send error: {:?}", e), ErrorKind::Unknown))?;
Expand Down
2 changes: 1 addition & 1 deletion core/startos/src/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use futures::future::BoxFuture;
use futures::{Future, FutureExt};
use imbl::Vector;
use imbl_value::{to_value, InternedString};
use patch_db::json_ptr::{ ROOT};
use patch_db::json_ptr::ROOT;

use crate::context::RpcContext;
use crate::prelude::*;
Expand Down

0 comments on commit 668a0b8

Please sign in to comment.