OLD | NEW |
1 import hashlib | 1 import hashlib |
2 import hmac | 2 import hmac |
3 import json | 3 import json |
4 import logging | 4 import logging |
5 import time | 5 import time |
6 | 6 |
7 from google.appengine.api import app_identity | 7 from google.appengine.api import app_identity |
8 from google.appengine.api import mail | 8 from google.appengine.api import mail |
9 from google.appengine.ext import ndb | 9 from google.appengine.ext import ndb |
10 import webapp2 | 10 import webapp2 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 self.response.out.write('json build format is incorrect') | 160 self.response.out.write('json build format is incorrect') |
161 self.error(400) | 161 self.error(400) |
162 return | 162 return |
163 | 163 |
164 # Emails can only come from the app ID, so we split on '@' here just in | 164 # Emails can only come from the app ID, so we split on '@' here just in |
165 # case the user specified a full email address. | 165 # case the user specified a full email address. |
166 from_addr_prefix = build_data.get('from_addr', 'buildbot').split('@')[0] | 166 from_addr_prefix = build_data.get('from_addr', 'buildbot').split('@')[0] |
167 from_addr = from_addr_prefix + '@%s.appspotmail.com' % ( | 167 from_addr = from_addr_prefix + '@%s.appspotmail.com' % ( |
168 app_identity.get_application_id()) | 168 app_identity.get_application_id()) |
169 | 169 |
| 170 subject_template = build_data.get('subject_template') |
| 171 |
170 recipients = ', '.join(build_data['recipients']) | 172 recipients = ', '.join(build_data['recipients']) |
171 | 173 |
172 template = gatekeeper_mailer.MailTemplate(build_data['waterfall_url'], | 174 template = gatekeeper_mailer.MailTemplate(build_data['waterfall_url'], |
173 build_data['build_url'], | 175 build_data['build_url'], |
174 build_data['project_name'], | 176 build_data['project_name'], |
175 from_addr) | 177 from_addr, |
| 178 subject=subject_template) |
176 | 179 |
177 | 180 |
178 text_content, html_content, subject = template.genMessageContent(build_data) | 181 text_content, html_content, subject = template.genMessageContent(build_data) |
179 | 182 |
180 mail_override = ['stip@chromium.org', | 183 mail_override = ['stip@chromium.org', |
181 'gatekeeper-ng@chromium-gatekeeper-sentry.appspotmail.com'] | 184 'gatekeeper-ng@chromium-gatekeeper-sentry.appspotmail.com'] |
182 | 185 |
183 message = mail.EmailMessage(sender=from_addr, | 186 message = mail.EmailMessage(sender=from_addr, |
184 subject=subject, | 187 subject=subject, |
185 #to=recipients, | 188 #to=recipients, |
186 to=mail_override, | 189 to=mail_override, |
187 body=text_content, | 190 body=text_content, |
188 html=html_content) | 191 html=html_content) |
189 logging.info('sending email to %s', recipients) | 192 logging.info('sending email to %s', recipients) |
190 logging.info('sending from %s', from_addr) | 193 logging.info('sending from %s', from_addr) |
191 logging.info('subject is %s', subject) | 194 logging.info('subject is %s', subject) |
192 message.send() | 195 message.send() |
193 self.response.out.write('email sent') | 196 self.response.out.write('email sent') |
194 | 197 |
195 | 198 |
196 app = webapp2.WSGIApplication([('/mailer', MainPage), | 199 app = webapp2.WSGIApplication([('/mailer', MainPage), |
197 ('/mailer/email', Email)], | 200 ('/mailer/email', Email)], |
198 debug=True) | 201 debug=True) |
OLD | NEW |