File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,8 @@ TURNSTILE_SECRET=none
81
81
SMTP_USERNAME = none
82
82
SMTP_PASSWORD = none
83
83
SMTP_HOST = none
84
+ SMTP_PORT = 25
85
+ SMTP_TLS = true
84
86
85
87
SITE_VERIFY_EMAIL_PATH = none
86
88
SITE_RESET_PASSWORD_PATH = none
@@ -105,4 +107,4 @@ STRIPE_WEBHOOK_SECRET=none
105
107
106
108
ADITUDE_API_KEY = none
107
109
108
- PYRO_API_KEY = none
110
+ PYRO_API_KEY = none
Original file line number Diff line number Diff line change 1
1
use lettre:: message:: header:: ContentType ;
2
2
use lettre:: message:: Mailbox ;
3
3
use lettre:: transport:: smtp:: authentication:: Credentials ;
4
+ use lettre:: transport:: smtp:: client:: { Tls , TlsParameters } ;
4
5
use lettre:: { Address , Message , SmtpTransport , Transport } ;
5
6
use thiserror:: Error ;
6
7
@@ -34,9 +35,20 @@ pub fn send_email_raw(
34
35
let username = dotenvy:: var ( "SMTP_USERNAME" ) ?;
35
36
let password = dotenvy:: var ( "SMTP_PASSWORD" ) ?;
36
37
let host = dotenvy:: var ( "SMTP_HOST" ) ?;
38
+ let port = dotenvy:: var ( "SMTP_PORT" ) ?. parse :: < u16 > ( ) . unwrap_or ( 25 ) ;
37
39
let creds = Credentials :: new ( username, password) ;
40
+ let tls_settings =
41
+ if dotenvy:: var ( "SMTP_TLS" ) ?. parse :: < bool > ( ) . unwrap_or ( true ) {
42
+ Tls :: Wrapper ( TlsParameters :: new ( host. clone ( ) . into ( ) ) ?)
43
+ } else {
44
+ Tls :: None
45
+ } ;
38
46
39
- let mailer = SmtpTransport :: relay ( & host) ?. credentials ( creds) . build ( ) ;
47
+ let mailer = SmtpTransport :: relay ( & host) ?
48
+ . port ( port)
49
+ . tls ( tls_settings)
50
+ . credentials ( creds)
51
+ . build ( ) ;
40
52
41
53
mailer. send ( & email) ?;
42
54
Original file line number Diff line number Diff line change @@ -455,6 +455,8 @@ pub fn check_env_vars() -> bool {
455
455
failed |= check_var :: < String > ( "SMTP_USERNAME" ) ;
456
456
failed |= check_var :: < String > ( "SMTP_PASSWORD" ) ;
457
457
failed |= check_var :: < String > ( "SMTP_HOST" ) ;
458
+ failed |= check_var :: < u16 > ( "SMTP_PORT" ) ;
459
+ failed |= check_var :: < bool > ( "SMTP_TLS" ) ;
458
460
459
461
failed |= check_var :: < String > ( "SITE_VERIFY_EMAIL_PATH" ) ;
460
462
failed |= check_var :: < String > ( "SITE_RESET_PASSWORD_PATH" ) ;
You can’t perform that action at this time.
0 commit comments