Skip to content

Commit

Permalink
fix: smtp doesn't require username/password
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Dec 6, 2023
1 parent 8ad8d20 commit abb50fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
13 changes: 10 additions & 3 deletions backend/windmill-api/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ pub async fn test_email(
require_super_admin(&db, &authed.email).await?;
let smtp = test_email.smtp;
let to = test_email.to;
let client = SmtpClientBuilder::new(smtp.host, smtp.port)
.implicit_tls(smtp.tls_implicit)
.credentials((smtp.username, smtp.password));
let client = SmtpClientBuilder::new(smtp.host, smtp.port).implicit_tls(smtp.tls_implicit);
let client = if let (Some(username), Some(password)) = (smtp.username, smtp.password) {
if !username.is_empty() {
client.credentials((username, password))
} else {
client
}
} else {
client
};
let message = MessageBuilder::new()
.from(("Windmill", smtp.from.as_str()))
.to(to.clone())
Expand Down
13 changes: 10 additions & 3 deletions backend/windmill-api/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,9 +1665,16 @@ pub fn send_email_if_possible(subject: &str, content: &str, to: &str) {

pub async fn send_email_if_possible_intern(subject: &str, content: &str, to: &str) -> Result<()> {
if let Some(smtp) = SERVER_CONFIG.read().await.smtp.clone() {
let client = SmtpClientBuilder::new(smtp.host, smtp.port)
.implicit_tls(smtp.tls_implicit)
.credentials((smtp.username, smtp.password));
let client = SmtpClientBuilder::new(smtp.host, smtp.port).implicit_tls(smtp.tls_implicit);
let client = if let (Some(username), Some(password)) = (smtp.username, smtp.password) {
if !username.is_empty() {
client.credentials((username, password))
} else {
client
}
} else {
client
};
let message = MessageBuilder::new()
.from(("Windmill", smtp.from.as_str()))
.to(to)
Expand Down
8 changes: 4 additions & 4 deletions backend/windmill-common/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{error, DB};
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
pub struct Smtp {
pub host: String,
pub username: String,
pub password: String,
pub username: Option<String>,
pub password: Option<String>,
pub port: u16,
pub from: String,
pub tls_implicit: bool,
Expand All @@ -33,7 +33,7 @@ pub async fn load_server_config(db: &DB) -> error::Result<ServerConfig> {
.flatten()
.unwrap_or_default();

let config_smtp = if let (Some(host), Some(username), Some(password)) =
let config_smtp = if let (Some(host), username, password) =
(config.smtp_host, config.smtp_username, config.smtp_password)
{
Some(Smtp {
Expand All @@ -50,7 +50,7 @@ pub async fn load_server_config(db: &DB) -> error::Result<ServerConfig> {
None
};
let smtp = config_smtp.or(
if let (Some(host), Some(username), Some(password)) = (
if let (Some(host), username, password) = (
std::env::var("SMTP_HOST").ok(),
std::env::var("SMTP_USERNAME").ok(),
std::env::var("SMTP_PASSWORD").ok(),
Expand Down

0 comments on commit abb50fa

Please sign in to comment.