@@ -70,15 +70,23 @@ pub async fn update_user(
70
70
let email_address = user. verified_email ( & mut conn) . await ?;
71
71
72
72
if let Some ( email_address) = email_address {
73
- let email = PublishNotificationsUnsubscribeEmail {
74
- user_name : & user. gh_login ,
75
- domain : & state. emails . domain ,
76
- } ;
77
-
78
- if let Err ( error) = state. emails . send ( & email_address, email) . await {
79
- warn ! (
80
- "Failed to send publish notifications unsubscribe email to {email_address}: {error}"
81
- ) ;
73
+ let email = EmailMessage :: from_template (
74
+ "unsubscribe_notifications" ,
75
+ context ! {
76
+ user_name => user. gh_login,
77
+ domain => state. emails. domain
78
+ } ,
79
+ ) ;
80
+
81
+ match email {
82
+ Ok ( email) => {
83
+ if let Err ( error) = state. emails . send ( & email_address, email) . await {
84
+ warn ! (
85
+ "Failed to send publish notifications unsubscribe email to {email_address}: {error}"
86
+ ) ;
87
+ }
88
+ }
89
+ Err ( error) => warn ! ( "Failed to render unsubscribe email template: {error}" ) ,
82
90
}
83
91
}
84
92
}
@@ -129,25 +137,3 @@ pub async fn update_user(
129
137
130
138
Ok ( OkResponse :: new ( ) )
131
139
}
132
-
133
- pub struct PublishNotificationsUnsubscribeEmail < ' a > {
134
- pub user_name : & ' a str ,
135
- pub domain : & ' a str ,
136
- }
137
-
138
- impl crate :: email:: Email for PublishNotificationsUnsubscribeEmail < ' _ > {
139
- fn subject ( & self ) -> String {
140
- "crates.io: Unsubscribed from publish notifications" . into ( )
141
- }
142
-
143
- fn body ( & self ) -> String {
144
- let Self { user_name, domain } = self ;
145
- format ! (
146
- "Hello {user_name}!
147
-
148
- You have been unsubscribed from publish notifications.
149
-
150
- If you would like to resubscribe, please visit https://{domain}/settings/profile" ,
151
- )
152
- }
153
- }
0 commit comments