Skip to content

Commit

Permalink
use email domain from config
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr committed May 15, 2023
1 parent da44a27 commit 72159ae
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [".", "migration"]
async-lock = "2.7.0"
async-session = "3.0.0"
base64 = "0.21.0"
email_address = "0.2.4"
env_logger = "0.10.0"
fastrand = "1.9.0"
git-version = "0.3.5"
Expand Down
7 changes: 4 additions & 3 deletions src/clients/postmark_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
clients::{ClientConnExt, ClientError},
ApiConfig,
};
use email_address::EmailAddress;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::{json, Value};
use trillium::{async_trait, Conn, KnownHeaderName};
Expand All @@ -13,7 +14,7 @@ use url::Url;
pub struct PostmarkClient {
token: String,
client: Client,
email: String,
email: EmailAddress,
base_url: Url,
}

Expand All @@ -39,7 +40,7 @@ impl PostmarkClient {
email
.as_object_mut()
.unwrap()
.insert("From".into(), self.email.clone().into());
.insert("From".into(), self.email.to_string().into());
self.post("/email", &email).await
}

Expand All @@ -53,7 +54,7 @@ impl PostmarkClient {
let headers = match message_id {
Some(m) => json!([{
"Name": "Message-ID",
"Value": format!("<{m}>")
"Value": format!("<{m}@{}>", self.email.domain())
}]),
None => json!([]),
};
Expand Down
5 changes: 3 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::handler::oauth2::Oauth2Config;
use email_address::EmailAddress;
use std::{env::VarError, str::FromStr};
use thiserror::Error;
use trillium_client::Client;
Expand All @@ -22,7 +23,7 @@ pub struct ApiConfig {
pub prometheus_host: String,
pub prometheus_port: u16,
pub postmark_token: String,
pub email_address: String,
pub email_address: EmailAddress,
pub postmark_url: Url,
pub client: Client,
}
Expand Down Expand Up @@ -91,7 +92,7 @@ impl ApiConfig {
"16-bit number",
)?,
postmark_token: var("POSTMARK_TOKEN", "string")?,
email_address: var("EMAIL_ADDRESS", "string")?,
email_address: var("EMAIL_ADDRESS", "email")?,
postmark_url: Url::parse("https://api.postmarkapp.com").unwrap(),
client: Client::new(RustlsConfig::default().with_tcp_config(ClientConfig::default()))
.with_default_pool(),
Expand Down
2 changes: 1 addition & 1 deletion src/queue/job/v1/send_invitation_email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl SendInvitationEmail {
"account_name": &account.name,
"action_url": self.action_url
}),
Some(format!("{}@divviup.org", self.message_id)),
Some(self.message_id.to_string()),
)
.await?;

Expand Down
2 changes: 1 addition & 1 deletion tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn config(api_mocks: impl Handler) -> ApiConfig {
prometheus_host: "localhost".into(),
prometheus_port: 9464,
postmark_token: "-".into(),
email_address: "test@example.test".into(),
email_address: "test@example.test".parse().unwrap(),
postmark_url: POSTMARK_URL.parse().unwrap(),
client: Client::new(trillium_testing::connector(api_mocks)),
}
Expand Down

0 comments on commit 72159ae

Please sign in to comment.