Merge lp:~deadlight/canonical-identity-provider/email-template into lp:~deadlight/canonical-identity-provider/vanilla
- email-template
- Merge into vanilla
Proposed by
Karl Williams
Status: | Merged |
---|---|
Approved by: | Karl Williams |
Approved revision: | 1715 |
Merged at revision: | 1715 |
Proposed branch: | lp:~deadlight/canonical-identity-provider/email-template |
Merge into: | lp:~deadlight/canonical-identity-provider/vanilla |
Diff against target: |
393 lines (+274/-17) 2 files modified
src/identityprovider/emailutils.py (+27/-17) src/webui/templates/email/html/email.html (+247/-0) |
To merge this branch: | bzr merge lp:~deadlight/canonical-identity-provider/email-template |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Anthony Dillon (community) | Approve | ||
Review via email: mp+372011@code.launchpad.net |
Commit message
Description of the change
Added an HTML email template
QA:
In terminal 1:
- npm i
- ./node_
- source env/bin/activate
- make start-db
- make run
In terminal 2:
- source env/bin/activate
- make mail-debug
- Visit http://[CONTAINER IP]:8000/
- Create an account
- Check the output of terminal 2 and see the email text
- Copy the HTML email into a file and open it in a browser to view ityo
To post a comment you must log in.
Revision history for this message
Karl Williams (deadlight) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/identityprovider/emailutils.py' |
2 | --- src/identityprovider/emailutils.py 2018-08-22 22:33:08 +0000 |
3 | +++ src/identityprovider/emailutils.py 2019-08-29 15:29:29 +0000 |
4 | @@ -64,22 +64,28 @@ |
5 | return formataddr((name, address)) |
6 | |
7 | |
8 | -def send_templated_email(subject, template, context, email, from_address=None): |
9 | +def send_templated_email(subject, template, context, email, from_address=None, title=None): |
10 | msg = render_to_string(template, context=context) |
11 | |
12 | if from_address is None: |
13 | from_address = format_address(settings.NOREPLY_FROM_ADDRESS) |
14 | + if title is None: |
15 | + title = 'Ubuntu One' |
16 | + |
17 | + html = render_to_string('email/html/email.html', {'title':title, 'content':msg}) |
18 | + |
19 | if not isinstance(email, (tuple, list)): |
20 | email = [email] |
21 | return send_mail( |
22 | - subject, |
23 | - msg, |
24 | - from_address, |
25 | - [format_address(e) for e in email] |
26 | + subject = subject, |
27 | + message = msg, |
28 | + from_email = from_address, |
29 | + recipient_list = [format_address(e) for e in email], |
30 | + html_message = html |
31 | ) |
32 | |
33 | |
34 | -def send_fancy_email(subject, template, context, email, from_address=None): |
35 | +def send_fancy_email(subject, template, context, email, from_address=None, title=None): |
36 | if from_address is None: |
37 | from_address = format_address( |
38 | settings.NOREPLY_FROM_ADDRESS, |
39 | @@ -87,7 +93,7 @@ |
40 | ) |
41 | subject = u"%s: %s" % (settings.NOREPLY_FROM_NAME, subject) |
42 | return send_templated_email(subject, template, context, email, |
43 | - from_address) |
44 | + from_address, title) |
45 | |
46 | |
47 | def _should_add_invalidation_link(email): |
48 | @@ -178,7 +184,7 @@ |
49 | template = 'email/desktop-newuser.txt' |
50 | |
51 | send_fancy_email( |
52 | - _('Finish your registration'), template, context, email) |
53 | + _('Finish your registration'), template, context, email, None, 'Finish your registration') |
54 | return token, invalidate_email_token |
55 | |
56 | |
57 | @@ -219,7 +225,7 @@ |
58 | context, token, invalidate_email_token = _context_for_email_request( |
59 | root_url, account, email, AuthTokenType.PASSWORDRECOVERY, |
60 | redirection_url, requester_email=email) |
61 | - send_fancy_email(subject, template, context, email) |
62 | + send_fancy_email(subject, template, context, email, None, 'Password reset') |
63 | return token, invalidate_email_token |
64 | |
65 | |
66 | @@ -236,7 +242,7 @@ |
67 | send_fancy_email( |
68 | _("Password change notification"), |
69 | 'email/password-changed.txt', |
70 | - context=context, email=email.email) |
71 | + context=context, email=email.email, from_address=None, title='Password changed') |
72 | |
73 | |
74 | def send_printed_codes_renewal_email(root_url, account, devices): |
75 | @@ -257,7 +263,7 @@ |
76 | send_fancy_email( |
77 | _("Printed list of backup codes is nearly used up"), |
78 | 'email/printed-codes-nearly-exhausted-warning.txt', |
79 | - context=context, email=email) |
80 | + context=context, email=email, from_address=None, title='Backup codes') |
81 | |
82 | |
83 | def send_validation_email_request(root_url, account, email, |
84 | @@ -281,7 +287,7 @@ |
85 | requester_email=preferredemail_email, oid_token=oid_token) |
86 | send_fancy_email( |
87 | _("Validate your email address"), 'email/validate-email.txt', |
88 | - context, email) |
89 | + context, email, None, 'Validate your email address') |
90 | return token, invalidate_email_token |
91 | |
92 | |
93 | @@ -300,7 +306,8 @@ |
94 | send_fancy_email( |
95 | _("The email address {email} was removed from your account").format( |
96 | email=invalidated_email), |
97 | - 'email/email-invalidated.txt', context=context, email=email) |
98 | + 'email/email-invalidated.txt', context=context, email=email, |
99 | + from_address=None, title='Email address removed') |
100 | |
101 | |
102 | def send_notification_to_invalidated_email_address(root_url, account, |
103 | @@ -315,14 +322,16 @@ |
104 | ), |
105 | 'email/invalidate_email_confirmation.txt', |
106 | context=context, |
107 | - email=invalidated_email |
108 | + email=invalidated_email, |
109 | + from_address=None, |
110 | + title='Email address invalidated' |
111 | ) |
112 | |
113 | |
114 | def send_preferred_changed_notification(email, new_preferred): |
115 | send_fancy_email( |
116 | _('E-mail change notification'), 'email/preferred-changed.txt', |
117 | - {'new_preferred': new_preferred}, email) |
118 | + {'new_preferred': new_preferred}, email, None, 'Preferred email changed') |
119 | |
120 | |
121 | def send_invitation_after_password_reset(root_url, email): |
122 | @@ -330,7 +339,7 @@ |
123 | url = urljoin(root_url, reverse('new_account')) |
124 | send_fancy_email( |
125 | _("Password reset request"), 'email/invitation.txt', |
126 | - {'email': email, 'signup': url}, email, |
127 | + {'email': email, 'signup': url}, email, None, 'Password reset request' |
128 | ) |
129 | |
130 | |
131 | @@ -363,7 +372,8 @@ |
132 | else: |
133 | subject = _('Account to be deleted - action required') |
134 | send_fancy_email( |
135 | - subject, 'email/account-action-required.txt', context, email, |
136 | + subject, 'email/account-action-required.txt', context, email, None, |
137 | + 'Action required' |
138 | ) |
139 | return token, invalidate_email_token |
140 | |
141 | |
142 | === added directory 'src/webui/templates/email/html' |
143 | === added file 'src/webui/templates/email/html/email.html' |
144 | --- src/webui/templates/email/html/email.html 1970-01-01 00:00:00 +0000 |
145 | +++ src/webui/templates/email/html/email.html 2019-08-29 15:29:29 +0000 |
146 | @@ -0,0 +1,247 @@ |
147 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
148 | +<html xmlns="http://www.w3.org/1999/xhtml" |
149 | +xmlns:v="urn:schemas-microsoft-com:vml" |
150 | +xmlns:o="urn:schemas-microsoft-com:office:office"> |
151 | + |
152 | +<head> |
153 | + <!--[if gte mso 9]><xml> |
154 | + <o:OfficeDocumentSettings> |
155 | + <o:AllowPNG/> |
156 | + <o:PixelsPerInch>96</o:PixelsPerInch> |
157 | + </o:OfficeDocumentSettings> |
158 | + </xml><![endif]--> |
159 | + |
160 | + <!-- Define Charset --> |
161 | + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
162 | + |
163 | + <!-- Responsive Meta Tag --> |
164 | + <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> |
165 | + |
166 | + <link href="https://fonts.googleapis.com/css?family=Ubuntu:100,300,400,500,700" rel="stylesheet"> |
167 | + |
168 | + <title>{{ title }}</title> |
169 | + |
170 | + <!-- Responsive Styles and Valid Styles --> |
171 | + |
172 | + <style type="text/css"> |
173 | + /* iOS BLUE LINKS */ |
174 | + a[x-apple-data-detectors] { |
175 | + color: inherit !important; |
176 | + text-decoration: none !important; |
177 | + font-size: inherit !important; |
178 | + font-family: inherit !important; |
179 | + font-weight: inherit !important; |
180 | + line-height: inherit !important; |
181 | + } |
182 | + |
183 | + body{ |
184 | + width: 100%; |
185 | + background-color: #E1E1E1; |
186 | + margin:0; |
187 | + padding:0; |
188 | + -webkit-font-smoothing: antialiased; |
189 | + mso-margin-top-alt:0px; |
190 | + mso-margin-bottom-alt:0px; |
191 | + mso-padding-alt: 0px 0px 0px 0px; |
192 | + -webkit-text-size-adjust:none; |
193 | + } |
194 | + |
195 | + p,h1,h2,h3,h4{ |
196 | + margin-top:0; |
197 | + margin-bottom:0; |
198 | + padding-top:0; |
199 | + padding-bottom:0; |
200 | + } |
201 | + |
202 | + p { |
203 | + margin-bottom: 1em; |
204 | + } |
205 | + |
206 | + [style*="Ubuntu"] { |
207 | + font-family: Ubuntu, Sans Serif, Arial, Helvetica !important; |
208 | + } |
209 | + |
210 | + span.Preheader{display: none; font-size: 1px;} |
211 | + |
212 | + html{ |
213 | + width: 100%; |
214 | + } |
215 | + |
216 | + .ZedFix { |
217 | + display:none; |
218 | + display:none!important; |
219 | + } |
220 | + |
221 | + /* ----------- responsivity ----------- */ |
222 | + @media only screen and (max-width: 640px){ |
223 | + /*-------- Table --------*/ |
224 | + *[class=Table800] {width: 100% !important;} |
225 | + *[class=Table799] {width: 90% !important;} |
226 | + *[class=Table740] {width: 100% !important;} |
227 | + *[class=Tds200] {width: 150px !important; padding-left:0 !important;} |
228 | + *[class=Tds540] {width: 610px !important;} |
229 | + |
230 | + /*----- Image -------*/ |
231 | + *[class=Inbox] img{width: 50% !important; height: auto !important;} |
232 | + |
233 | + /*----- Others -------*/ |
234 | + *[class=Zwidth] {min-width:100% !important;} |
235 | + *[class=MobileHide] {display:none !important;} |
236 | + *[class=TextC] {text-align:center !important;} |
237 | + } |
238 | + |
239 | + @media only screen and (max-width: 479px){ |
240 | + /*-------- Table --------*/ |
241 | + *[class=Table800] {width: 100% !important; min-width:360px !important;} |
242 | + *[class=Tds200] {width: 110px !important; padding-left:0 !important;} |
243 | + *[class=Tds540] {width: 210px !important;} |
244 | + |
245 | + /*----- Image -------*/ |
246 | + *[class=Inbox] img{width: 50% !important; height: auto !important;} |
247 | + |
248 | + /*----- Others -------*/ |
249 | + *[class=Zwidth] {min-width:100% !important;} |
250 | + *[class=MobileHide] {display:none !important;} |
251 | + *[class=TextC] {text-align:center !important;} |
252 | + *[class=Fonts48] {font-size:35.65px !important; line-height:48px !important;} |
253 | + } |
254 | + </style> |
255 | +</head> |
256 | + |
257 | +<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> |
258 | + <table border="0" width="100%" cellpadding="0" cellspacing="0" bgcolor="#E1E1E1"> |
259 | + <tr> |
260 | + <td align="center" class="Zwidth" style="min-width:800px;"> |
261 | + <div class="mktEditable" id="Header"> |
262 | + <table align="center" width="800" border="0" cellspacing="0" cellpadding="0" bgcolor="#380426" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; width:800px;" class="Table800"> |
263 | + <tr> |
264 | + <td background="https://assets.ubuntu.com/v1/1d8ce799-email-hero-background.png?w=800" bgcolor="#380426" width="800" height="289" valign="top" style="background-image:url(https://assets.ubuntu.com/v1/1d8ce799-email-hero-background.png?w=800); background-position:top center; background-size:cover;"> |
265 | + <!--[if gte mso 9]> |
266 | + <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="width:800px;height:289px;"> |
267 | + <v:fill type="tile" src="https://assets.ubuntu.com/v1/1d8ce799-email-hero-background.png?w=800" color="#7D335B" /> |
268 | + <v:textbox inset="0,0,0,0"> |
269 | + <![endif]--> |
270 | + <div> |
271 | + <table align="center" width="800" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; width:800px;" class="Table799"> |
272 | + <tr> |
273 | + <td align="center"> |
274 | + <table align="center" width="740" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; width:740px;" class="Table740"> |
275 | + <tr> |
276 | + <td align="left" valign="bottom" style="padding: 65px 0 0;"> |
277 | + <img height="55" width="120" src="https://assets.ubuntu.com/v1/d738f754-Ubuntu_One_Mono_Logo.svg" /> |
278 | + </td> |
279 | + </tr> |
280 | + <tr> |
281 | + <td align="left" valign="bottom" class="Fonts48" style="color:#FFFFFF; font-family: Arial, Sans Serif, Ubuntu; font-size:46.5667px; line-height:56px; font-weight:100; font-style:normal; padding:30px 0 50px 0;"> |
282 | + {{ title }} |
283 | + </td> |
284 | + </tr> |
285 | + </table> |
286 | + </td> |
287 | + </tr> |
288 | + </table> |
289 | + </div> |
290 | + <!--[if gte mso 9]> |
291 | + </v:textbox> |
292 | + </v:rect> |
293 | + <![endif]--> |
294 | + </td> |
295 | + </tr> |
296 | + </table> |
297 | + </div> |
298 | + </td> |
299 | +</tr> |
300 | + |
301 | +<tr> |
302 | + <td align="center" class="Zwidth" style="min-width:800px;"> |
303 | + <div class="mktEditable" id="Primary_talking"> |
304 | + <table align="center" width="800" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; width:800px;" class="Table800"> |
305 | + <tr> |
306 | + <td align="center" style="padding:54px 20px"> |
307 | + <table align="center" width="740" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; width:740px;" class="Table740"> |
308 | + <tr> |
309 | + <td align="left" style="color:#0E0E0E; font-family: Arial, Sans Serif, Ubuntu; font-size:16px; line-height:24px; font-weight:300; font-style:normal; padding:16px 0 0 0"> |
310 | + {{ content|linebreaks|urlize }} |
311 | + </td> |
312 | + </tr> |
313 | + </table> |
314 | + </td> |
315 | + </tr> |
316 | + </table> |
317 | + </div> |
318 | + </td> |
319 | +</tr> |
320 | + |
321 | +<tr> |
322 | + <td align="center" class="Zwidth" style="min-width:800px;"> |
323 | + <div class="mktEditable" id="Footer"> |
324 | + <table align="center" width="800" cellpadding="0" bgcolor="#F7F7F7" border="0" cellspacing="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; width:800px;" class="Table800"> |
325 | + <tr> |
326 | + <td align="center" style="padding:40px 20px 0 20px;"> |
327 | + <table align="center" width="740" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; width:740px;" class="Table740"> |
328 | + <tr> |
329 | + <td align="left"> |
330 | + <table align="left" width="167" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; width:167px;" class="Table740"> |
331 | + <tr> |
332 | + <td align="center"> |
333 | + <table align="center" width="167" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;"> |
334 | + <tr> |
335 | + <td align="left" valign="middle" width="32"> |
336 | + <a href="https://www.linkedin.com/company/ubuntu/" target="_blank"> <img src="https://assets.ubuntu.com/v1/885320bd-social-linkedin.png" width="32" height="32" border="0" style="display:block; width:32px; height:32px" alt="" /> </a> |
337 | + </td> |
338 | + <td align="left" valign="middle" width="13"> </td> |
339 | + <td align="left" valign="middle" width="32"> |
340 | + <a href="https://twitter.com/ubuntu" target="_blank"> <img src="https://assets.ubuntu.com/v1/28569fb0-social-twitter.png" width="32" height="32" border="0" style="display:block; width:32px; height:32px" alt="" /> </a> |
341 | + </td> |
342 | + <td align="left" valign="middle" width="13"> </td> |
343 | + <td align="left" valign="middle" width="32"> |
344 | + <a href="https://www.facebook.com/ubuntulinux/" target="_blank"> <img src="https://assets.ubuntu.com/v1/63b1275f-social-facebook.png" width="32" height="32" border="0" style="display:block; width:32px; height:32px" alt="" /> </a> |
345 | + </td> |
346 | + </tr> |
347 | + </table> |
348 | + </td> |
349 | + </tr> |
350 | + </table> |
351 | + </td> |
352 | + </tr> |
353 | + <tr> |
354 | + <td align="left" class="TextC" style="color:#000000; font-family: Arial, Sans Serif, Ubuntu; font-size:16px; line-height:24px; font-weight:300; font-style:normal; padding:20px 0 5px 0"> |
355 | + <a style="color:#000000; text-decoration:none" href="http://www.canonical.com" target="_blank">www.canonical.com</a> | <a style="color:#000000; text-decoration:none" href="http://www.ubuntu.com" target="_blank">www.ubuntu.com</a> |
356 | + </td> |
357 | + </tr> |
358 | + <tr> |
359 | + <td align="left" class="TextC" style="color:#000000; font-family: Arial, Sans Serif, Ubuntu; font-size:14px; line-height:22px; font-weight:300; font-style:normal; padding:0 0 50px 0"> |
360 | + © 2019 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd. |
361 | + </td> |
362 | + </tr> |
363 | + </table> |
364 | + </td> |
365 | + </tr> |
366 | + </table> |
367 | + </div> |
368 | + </td> |
369 | +</tr> |
370 | + |
371 | +<tr> |
372 | + <td align="center" class="Zwidth" style="min-width:800px"> |
373 | + <table align="center" width="800" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; width:800px;" class="Table800"> |
374 | + <tr> |
375 | + <td align="left" class="Inbox" valign="top" width="50%"> |
376 | + <img src="https://assets.ubuntu.com/v1/99e75450-inbox.png" width="400" height="1" border="0" style="display:block; width:400px; height:1px;" alt="" /> |
377 | + </td> |
378 | + <td align="right" class="Inbox" valign="top" width="50%"> |
379 | + <img src="https://assets.ubuntu.com/v1/99e75450-inbox.png" width="400" height="1" border="0" style="display:block; width:400px; height:1px;" alt="" /> |
380 | + </td> |
381 | + </tr> |
382 | + </table> |
383 | + </td> |
384 | +</tr> |
385 | +</table> |
386 | +<div class="ZedFix" style="white-space:nowrap; font:15px courier; line-height:0;"> |
387 | + |
388 | + |
389 | + |
390 | +</div> |
391 | + |
392 | +</body> |
393 | +</html> |
Example email output: https:/ /pastebin. canonical. com/p/77QvsTF4B Y/