@@ -30,7 +30,7 @@ lazy_static! {
30
30
31
31
#[ derive( Clone ) ]
32
32
pub struct EmailEvent {
33
- tx : Arc < tokio :: sync :: mpsc :: UnboundedSender < EmailType > > ,
33
+ tx : Arc < AsyncSmtpTransport < Tokio1Executor > > ,
34
34
}
35
35
36
36
impl EmailEvent {
@@ -42,35 +42,23 @@ impl EmailEvent {
42
42
. credentials ( creds)
43
43
. build ( ) ;
44
44
45
- let ( tx, rx) = tokio:: sync:: mpsc:: unbounded_channel ( ) ;
46
- tokio:: spawn ( async move {
47
- EmailEvent :: listen ( rx, mailer) . await ;
48
- } ) ;
49
- Ok ( EmailEvent { tx : Arc :: new ( tx) } )
45
+ Ok ( EmailEvent { tx : Arc :: new ( mailer) } )
50
46
}
51
47
pub async fn send ( & self , email_type : EmailType ) {
52
- self . tx . send ( email_type) . ok ( ) ;
53
- }
54
- pub async fn listen (
55
- mut rx : tokio:: sync:: mpsc:: UnboundedReceiver < EmailType > ,
56
- mailer : AsyncSmtpTransport < Tokio1Executor > ,
57
- ) {
58
- while let Some ( email_type) = rx. recv ( ) . await {
59
- info ! ( "Will Send Email to {:?}" , email_type) ;
60
- match email_type {
61
- EmailType :: Captcha ( x) => {
62
- let email = Message :: builder ( )
63
- . from ( SMTP_USERNAME . to_owned ( ) . parse ( ) . unwrap ( ) )
64
- . reply_to ( SMTP_USERNAME . to_owned ( ) . parse ( ) . unwrap ( ) )
65
- . to ( x. email . parse ( ) . unwrap ( ) )
66
- . subject ( "GitData Code" )
67
- . header ( ContentType :: TEXT_HTML )
68
- . body ( CAPTCHA . replace ( "123456" , & * x. code ) )
69
- . unwrap ( ) ;
70
- match mailer. send ( email) . await {
71
- Ok ( _) => info ! ( "Email sent {} successfully!" , x. email) ,
72
- Err ( e) => error ! ( "Could not send email: {e:?}" ) ,
73
- }
48
+ info ! ( "Will Send Email to {:?}" , email_type) ;
49
+ match email_type {
50
+ EmailType :: Captcha ( x) => {
51
+ let email = Message :: builder ( )
52
+ . from ( SMTP_USERNAME . to_owned ( ) . parse ( ) . unwrap ( ) )
53
+ . reply_to ( SMTP_USERNAME . to_owned ( ) . parse ( ) . unwrap ( ) )
54
+ . to ( x. email . parse ( ) . unwrap ( ) )
55
+ . subject ( "GitData Code" )
56
+ . header ( ContentType :: TEXT_HTML )
57
+ . body ( CAPTCHA . replace ( "123456" , & * x. code ) )
58
+ . unwrap ( ) ;
59
+ match self . tx . send ( email) . await {
60
+ Ok ( _) => info ! ( "Email sent {} successfully!" , x. email) ,
61
+ Err ( e) => error ! ( "Could not send email: {e:?}" ) ,
74
62
}
75
63
}
76
64
}
0 commit comments