-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow specifying the smtp port via config (#395)
Also, update READMEs to add instructions for how to start a local smtp server for dev/testing. Also, don't run pre-push checks against entire workspace, just roadster
- Loading branch information
1 parent
c94e291
commit 9f1b19b
Showing
6 changed files
with
68 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,10 @@ | |
from = "[email protected]" | ||
|
||
[email.smtp.connection] | ||
# The `smtps` scheme should be used in production | ||
uri = "smtp://localhost:1025" | ||
# Alternatively, provide connection details as individual fields | ||
#host = "smtp.example.com" | ||
#port = 465 | ||
#username = "username" | ||
#password = "password" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ impl Validate for SmtpConnection { | |
#[non_exhaustive] | ||
pub struct SmtpConnectionFields { | ||
pub host: String, | ||
pub port: Option<u16>, | ||
pub username: String, | ||
pub password: String, | ||
} | ||
|
@@ -69,7 +70,15 @@ impl TryFrom<&SmtpConnection> for SmtpTransportBuilder { | |
SmtpConnection::Fields(fields) => { | ||
let credentials = | ||
Credentials::new(fields.username.clone(), fields.password.clone()); | ||
SmtpTransport::relay(&fields.host).map(|builder| builder.credentials(credentials)) | ||
SmtpTransport::relay(&fields.host) | ||
.map(|builder| { | ||
if let Some(port) = fields.port { | ||
builder.port(port) | ||
} else { | ||
builder | ||
} | ||
}) | ||
.map(|builder| builder.credentials(credentials)) | ||
} | ||
SmtpConnection::Uri(fields) => SmtpTransport::from_url(fields.uri.as_ref()), | ||
} | ||
|
@@ -153,6 +162,17 @@ mod tests { | |
uri = "smtps://username:[email protected]:425" | ||
"# | ||
)] | ||
#[case( | ||
r#" | ||
from = "[email protected]" | ||
[smtp.connection] | ||
host = "smtp.example.com" | ||
port = 465 | ||
username = "username" | ||
password = "password" | ||
"# | ||
)] | ||
#[cfg_attr(coverage_nightly, coverage(off))] | ||
fn serialization(_case: TestCase, #[case] config: &str) { | ||
let email: Email = toml::from_str(config).unwrap(); | ||
|
10 changes: 10 additions & 0 deletions
10
src/config/email/snapshots/roadster__config__email__smtp__tests__serialization@case_6.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
source: src/config/email/smtp.rs | ||
expression: email | ||
--- | ||
from = '[email protected]' | ||
[smtp.connection] | ||
host = 'smtp.example.com' | ||
port = 465 | ||
username = 'username' | ||
password = 'password' |