def when_failed(ign): try: headers = { "From": FROM_ADDRESS, "Subject": "Sign-up error", } send_plain_email('*****@*****.**', '*****@*****.**', "A sign-up failed for <%s>." % (customer.email,), headers) except Exception: traceback.print_tb(100, self._log)
def send_monitoring_report(errors, from_email, what): if errors: content = MONITORING_EMAIL_BODY_BROKEN % {"errors": errors, "what": what} else: content = MONITORING_EMAIL_BODY_WORKING % {"what": what} headers = { "From": "Monitoring <%s>" % (from_email,), "Subject": MONITORING_EMAIL_SUBJECT % {"what": what}, } d = send_plain_email(from_email, TO_EMAIL, content, headers) d.addBoth(lambda ign: send_plain_email(from_email, TO_EMAIL2, content, headers)) return d
def send_monitoring_report(errors): if errors: content = MONITORING_EMAIL_BODY_BROKEN % (errors,) else: content = MONITORING_EMAIL_BODY_WORKING headers = { "From": FROM_ADDRESS, "Subject": MONITORING_EMAIL_SUBJECT, } d = send_plain_email(FROM_EMAIL, TO_EMAIL, content, headers) d.addBoth(lambda ign: send_plain_email(FROM_EMAIL, TO_EMAIL2, content, headers)) return d
def send_monitoring_report(errors): if errors: content = MONITORING_EMAIL_BODY_BROKEN % (errors, ) else: content = MONITORING_EMAIL_BODY_WORKING headers = { "From": FROM_ADDRESS, "Subject": MONITORING_EMAIL_SUBJECT, } d = send_plain_email(FROM_EMAIL, TO_EMAIL, content, headers) d.addBoth( lambda ign: send_plain_email(FROM_EMAIL, TO_EMAIL2, content, headers)) return d
def handle_stripe_create_customer_errors(self, trace_back, error, details, email_subject, notes=''): print >>self.out, "Got %s from the stripe.Customer.create call:" % (error.__class__.__name__,) print >>self.out, trace_back headers = { "From": FROM_ADDRESS, "Subject": email_subject, } if notes: combination = "%s\n%s" % (notes, trace_back) body = combination else: body = trace_back send_plain_email('*****@*****.**', '*****@*****.**', body, headers) raise RenderErrorDetailsForBrowser(details)
def mail(self, from_addr, to_addr, subject, headers): return send_plain_email( from_addr, to_addr, subject, headers, )
def send_notify_failure(f, customer_email, ignored, stdout, stderr): print >> stderr, str(f) content = NOTIFY_FAILURE_BODY % { "customer_email": customer_email, } headers = { "From": FROM_ADDRESS, "Subject": NOTIFY_FAILURE_SUBJECT, } d = send_plain_email(FROM_EMAIL, NOTIFY_FAILURE_EMAIL, content, headers) def _sent(ign): print >> stdout, "Failure notification email sent to %s." % ( NOTIFY_FAILURE_EMAIL, ) def _error(emailf): print >> stdout, "A failure notification could not be sent." print >> stderr, str(emailf) d.addCallbacks(_sent, _error) # return the original failure d.addBoth(lambda ign: f) return d
def send_notify_failure(f, customer_name, customer_email, logfilename, stdout, stderr, password_path='../secret_config/smtppassword'): password = FilePath(password_path).getContent().strip() print >>stderr, str(f) content = NOTIFY_FAILURE_BODY % { "customer_name": customer_name, "customer_email": customer_email, "logfilename": logfilename, } headers = { "From": FROM_ADDRESS, "Subject": NOTIFY_FAILURE_SUBJECT, "User-Agent": USER_AGENT, "Content-Type": 'text/plain; charset="utf-8"', } d = send_plain_email(SMTP_HOST, SMTP_USERNAME, password, FROM_EMAIL, NOTIFY_FAILURE_EMAIL, content, headers, SENDER_DOMAIN, SMTP_PORT) def _sent(ign): print >>stdout, "Failure notification sent for the following error:" def _error(emailf): print >>stdout, "A failure notification could not be sent." print >>stdout, "Contacting <%s> yourself may help to resolve this problem more quickly:" % (NOTIFY_FAILURE_EMAIL,) print >>stderr, str(emailf) d.addCallbacks(_sent, _error) # return the original failure d.addBoth(lambda ign: f) return d
def send_signup_confirmation(publichost, customer_name, customer_email, external_introducer_furl, customer_keyinfo, stdout, stderr): # TODO: the name is URL-escaped UTF-8. It should be OK to unescape it since the email is plain text, # but I'm being cautious for now since I haven't reviewed email.mime.text.MIMEText to make sure that's safe. content = CONFIRMATION_EMAIL_BODY % { "customer_name": customer_name, "external_introducer_furl": external_introducer_furl, "publichost": publichost } headers = { "From": FROM_ADDRESS, "Subject": CONFIRMATION_EMAIL_SUBJECT, } d = defer.succeed(None) if customer_keyinfo: print >> stdout, "Notifying one of our staff to send the confirmation e-mail to <%s>..." % ( customer_email, ) # Don't send the introducer furl; they're supposed to log in to the automation server to get it. headers["Subject"] = "Sign-up with PGP key" d.addCallback(lambda ign: send_plain_email( FROM_EMAIL, PGP_NOTIFICATION_EMAIL, "Please send a confirmation e-mail to %r at %r." % (customer_name, customer_email), headers)) else: print >> stdout, "Sending confirmation e-mail to <%s>..." % ( customer_email, ) d.addCallback(lambda ign: send_plain_email(FROM_EMAIL, customer_email, content, headers)) def _sent(ign): if customer_keyinfo: print >> stdout, "Notification sent." else: print >> stdout, "Confirmation e-mail sent." def _error(f): print >> stdout, "Sending of e-mail failed." print >> stdout, "Please contact <*****@*****.**> to make sure that we have your correct e-mail address." print >> stderr, str(f) return f d.addCallbacks(_sent, _error) return d
def send_signup_confirmation(publichost, customer_name, customer_email, external_introducer_furl, customer_keyinfo, stdout, stderr, password_path='../secret_config/smtppassword'): password = FilePath(password_path).getContent().strip() # TODO: the name is URL-escaped UTF-8. It should be OK to unescape it since the email is plain text, # but I'm being cautious for now since I haven't reviewed email.mime.text.MIMEText to make sure that's safe. content = CONFIRMATION_EMAIL_BODY % { "customer_name": customer_name, "external_introducer_furl": external_introducer_furl, "publichost": publichost } headers = { "From": FROM_ADDRESS, "Subject": CONFIRMATION_EMAIL_SUBJECT, "User-Agent": USER_AGENT, "Content-Type": 'text/plain; charset="utf-8"', } d = defer.succeed(None) if customer_keyinfo: print >>stdout, "Notifying one of our staff to send the confirmation e-mail to <%s>..." % (customer_email,) # Don't send the introducer furl; they're supposed to log in to the automation server to get it. headers["Subject"] = "Sign-up with PGP key" d.addCallback(lambda ign: send_plain_email(SMTP_HOST, SMTP_USERNAME, password, FROM_EMAIL, PGP_NOTIFICATION_EMAIL, "Please send a confirmation e-mail to %r at %r." % (customer_name, customer_email), headers, SENDER_DOMAIN, SMTP_PORT)) else: print >>stdout, "Sending confirmation e-mail to <%s>..." % (customer_email,) d.addCallback(lambda ign: send_plain_email(SMTP_HOST, SMTP_USERNAME, password, FROM_EMAIL, customer_email, content, headers, SENDER_DOMAIN, SMTP_PORT)) def _sent(ign): if customer_keyinfo: print >>stdout, "Notification sent." else: print >>stdout, "Confirmation e-mail sent." def _error(f): print >>stdout, "Sending of e-mail failed." print >>stdout, "Please contact <*****@*****.**> to make sure that we have your correct e-mail address." print >>stderr, str(f) return f d.addCallbacks(_sent, _error) return d
def send_bulletin(publichost, customer_name, customer_email, customer_keyinfo, stdout, stderr, password_path='../secret_config/smtppassword'): password = FilePath(password_path).getContent().strip() # TODO: the name is URL-escaped UTF-8. It should be OK to unescape it since the email is plain text, # but I'm being cautious for now since I haven't reviewed email.mime.text.MIMEText to make sure that's safe. content = bulletinbody_01 % { "customer_name": customer_name, "publichost": publichost } headers = { "From": FROM_ADDRESS, "Subject": bulletinsubject_01, "User-Agent": USER_AGENT, "Content-Type": 'text/plain; charset="utf-8"' } d = defer.succeed(None) if customer_keyinfo: print >>stdout, "Notifying one of our staff to send an update bulletin e-mail to <%s>..." % (customer_email,) headers["Subject"] = "PGP key enabled: "+bulletinsubject_01 d.addCallback(lambda ign: send_plain_email(SMTP_HOST, SMTP_USERNAME, password, FROM_EMAIL, PGP_NOTIFICATION_EMAIL, "Please send an update bulletin, e-mail to %r at %r." % (customer_name, customer_email), headers, SENDER_DOMAIN, SMTP_PORT)) else: print >>stdout, "Sending update bulletin e-mail to <%s>..." % (customer_email) d.addCallback(lambda ign: send_plain_email(SMTP_HOST, SMTP_USERNAME, password, FROM_EMAIL, customer_email, content, headers, SENDER_DOMAIN, SMTP_PORT)) def _sent(ign): if customer_keyinfo: print >>stdout, "PGP Encrypted Bulletin sent." else: print >>stdout, "Bulletin sent." def _error(f): print >>stdout, "Sending of bulletin e-mail failed." print >>stdout, "Please contact <*****@*****.**> to make sure that we have your correct e-mail address." print >>stderr, str(f) return f d.addCallbacks(_sent, _error) return d
def send_autoreply(customer_email, full_product_name): content = AUTOREPLY_EMAIL_BODY % { "full_product_name": full_product_name, } headers = { "From": FROM_ADDRESS, "Subject": AUTOREPLY_EMAIL_SUBJECT % {"full_product_name": full_product_name}, } d = send_plain_email(FROM_EMAIL, customer_email, content, headers) return d
def send_monitoring_report(errors, password_path='../secret_config/smtppassword'): password = FilePath(password_path).getContent().strip() if errors: content = MONITORING_EMAIL_BODY_BROKEN % (errors,) else: content = MONITORING_EMAIL_BODY_WORKING headers = { "From": FROM_ADDRESS, "Subject": MONITORING_EMAIL_SUBJECT, "User-Agent": USER_AGENT, "Content-Type": 'text/plain; charset="utf-8"', } d = send_plain_email(SMTP_HOST, SMTP_USERNAME, password, FROM_EMAIL, TO_EMAIL, content, headers, SENDER_DOMAIN, SMTP_PORT) d.addBoth(lambda ign: send_plain_email(SMTP_HOST2, SMTP_USERNAME2, '', FROM_EMAIL, TO_EMAIL2, content, headers, SENDER_DOMAIN, SMTP_PORT, requireSSL=False)) return d
def send_bulletin(publichost, customer_name, customer_email, customer_keyinfo, stdout, stderr): # TODO: the name is URL-escaped UTF-8. It should be OK to unescape it since the email is plain text, # but I'm being cautious for now since I haven't reviewed email.mime.text.MIMEText to make sure that's safe. content = bulletinbody_01 % { "customer_name": customer_name, "publichost": publichost } headers = { "From": FROM_ADDRESS, "Subject": bulletinsubject_01, } d = defer.succeed(None) if customer_keyinfo: print >> stdout, "Notifying one of our staff to send an update bulletin e-mail to <%s>..." % ( customer_email, ) headers["Subject"] = "PGP key enabled: " + bulletinsubject_01 d.addCallback(lambda ign: send_plain_email( FROM_EMAIL, PGP_NOTIFICATION_EMAIL, "Please send an update bulletin, e-mail to %r at %r." % (customer_name, customer_email), headers)) else: print >> stdout, "Sending update bulletin e-mail to <%s>..." % ( customer_email) d.addCallback(lambda ign: send_plain_email(FROM_EMAIL, customer_email, content, headers)) def _sent(ign): if customer_keyinfo: print >> stdout, "PGP Encrypted Bulletin sent." else: print >> stdout, "Bulletin sent." def _error(f): print >> stdout, "Sending of bulletin e-mail failed." print >> stderr, str(f) return f d.addCallbacks(_sent, _error) return d
def handle_stripe_create_customer_errors(self, trace_back, error, details, email_subject, notes=''): print >> self.out, "Got %s from the stripe.Customer.create call:" % ( error.__class__.__name__, ) print >> self.out, trace_back headers = { "From": FROM_ADDRESS, "Subject": email_subject, } if notes: combination = "%s\n%s" % (notes, trace_back) body = combination else: body = trace_back send_plain_email('*****@*****.**', '*****@*****.**', body, headers) raise RenderErrorDetailsForBrowser(details)
def send_signup_confirmation(publichost, customer_email, external_introducer_furl, customer_keyinfo, stdout, stderr): # TODO: the name is URL-escaped UTF-8. It should be OK to unescape it since the email is plain text, # but I'm being cautious for now since I haven't reviewed email.mime.text.MIMEText to make sure that's safe. content = CONFIRMATION_EMAIL_BODY % { "external_introducer_furl": external_introducer_furl, "publichost": publichost } headers = { "From": FROM_ADDRESS, "Subject": CONFIRMATION_EMAIL_SUBJECT, } d = defer.succeed(None) if customer_keyinfo: print >>stdout, "Notifying one of our staff to send the confirmation e-mail to <%s>..." % (customer_email,) # Don't send the introducer furl; they're supposed to log in to the automation server to get it. headers["Subject"] = "Sign-up with PGP key" d.addCallback(lambda ign: send_plain_email(FROM_EMAIL, PGP_NOTIFICATION_EMAIL, "Please send a confirmation e-mail to %r." % (customer_email), headers)) else: print >>stdout, "Sending confirmation e-mail to <%s>..." % (customer_email,) d.addCallback(lambda ign: send_plain_email(FROM_EMAIL, customer_email, content, headers)) def _sent(ign): if customer_keyinfo: print >>stdout, "Notification sent." else: print >>stdout, "Confirmation e-mail sent." def _error(f): print >>stdout, "Sending of e-mail failed." print >>stdout, "Please contact <*****@*****.**> to make sure that we have your correct e-mail address." print >>stderr, str(f) return f d.addCallbacks(_sent, _error) return d
def send_bulletin(publichost, customer_name, customer_email, customer_keyinfo, stdout, stderr): # TODO: the name is URL-escaped UTF-8. It should be OK to unescape it since the email is plain text, # but I'm being cautious for now since I haven't reviewed email.mime.text.MIMEText to make sure that's safe. content = bulletinbody_01 % { "customer_name": customer_name, "publichost": publichost } headers = { "From": FROM_ADDRESS, "Subject": bulletinsubject_01, } d = defer.succeed(None) if customer_keyinfo: print >>stdout, "Notifying one of our staff to send an update bulletin e-mail to <%s>..." % (customer_email,) headers["Subject"] = "PGP key enabled: "+bulletinsubject_01 d.addCallback(lambda ign: send_plain_email(FROM_EMAIL, PGP_NOTIFICATION_EMAIL, "Please send an update bulletin, e-mail to %r at %r." % (customer_name, customer_email), headers)) else: print >>stdout, "Sending update bulletin e-mail to <%s>..." % (customer_email) d.addCallback(lambda ign: send_plain_email(FROM_EMAIL, customer_email, content, headers)) def _sent(ign): if customer_keyinfo: print >>stdout, "PGP Encrypted Bulletin sent." else: print >>stdout, "Bulletin sent." def _error(f): print >>stdout, "Sending of bulletin e-mail failed." print >>stderr, str(f) return f d.addCallbacks(_sent, _error) return d
def send_autoreply(customer_email, full_product_name, signup_url): # TODO: the name is URL-escaped UTF-8. It should be OK to unescape it since the email is plain text, # but I'm being cautious for now since I haven't reviewed email.mime.text.MIMEText to make sure that's safe. if signup_url is None: content = AUTOREPLY_NOT_READY_EMAIL_BODY % { "full_product_name": full_product_name, } else: content = AUTOREPLY_READY_EMAIL_BODY % { "full_product_name": full_product_name, "signup_url": signup_url, } headers = { "From": FROM_ADDRESS, "Subject": AUTOREPLY_EMAIL_SUBJECT % {"full_product_name": full_product_name}, } d = send_plain_email(FROM_EMAIL, customer_email, content, headers) return d
def send_notify_failure(f, customer_email, ignored, stdout, stderr): print >>stderr, str(f) content = NOTIFY_FAILURE_BODY % { "customer_email": customer_email, } headers = { "From": FROM_ADDRESS, "Subject": NOTIFY_FAILURE_SUBJECT, } d = send_plain_email(FROM_EMAIL, NOTIFY_FAILURE_EMAIL, content, headers) def _sent(ign): print >>stdout, "Failure notification email sent to %s." % (NOTIFY_FAILURE_EMAIL,) def _error(emailf): print >>stdout, "A failure notification could not be sent." print >>stderr, str(emailf) d.addCallbacks(_sent, _error) # return the original failure d.addBoth(lambda ign: f) return d
def mail(self, subject, headers): return send_plain_email( self.from_addr, self.to_addr, subject, headers, )
if len(sys.argv) < 10: print "Usage: python test_email.py SMTP_HOST SMTP_USERNAME SMTP_PASSWORD FROM_EMAIL TO_EMAIL SUBJECT SENDER_DOMAIN SMTP_PORT REQUIRE_SSL" print "REQUIRE_SSL = 0|1" print "Happy email testing!" sys.exit(1) smtphost = sys.argv[1] smtpusername = sys.argv[2] smtppassword = sys.argv[3] fromemail = sys.argv[4] toemail = sys.argv[5] subject = sys.argv[6] senderdomain = sys.argv[7] smtpport = int(sys.argv[8]) requiressl = bool(int(sys.argv[9])) def cb(x): print str(x) if isinstance(x, Failure) and hasattr(x.value, 'response'): print x.value.response d = send_plain_email(smtphost, smtpusername, smtppassword, fromemail, toemail, "Hello, this is a test.", {"From": fromemail, "Subject": subject}, senderdomain, smtpport, requiressl) d.addBoth(cb) d.addCallbacks(lambda ign: os._exit(0), lambda ign: os._exit(1)) reactor.run()
import os, sys from twisted.internet import reactor from twisted.python.failure import Failure from lae_util.send_email import send_plain_email, FROM_EMAIL if len(sys.argv) < 4: print "Usage: python test_email.py FROM_ADDRESS TO_EMAIL SUBJECT" print "Happy email testing!" sys.exit(1) from_address = sys.argv[1] to_email = sys.argv[2] subject = sys.argv[3] def cb(x): print str(x) if isinstance(x, Failure) and hasattr(x.value, 'response'): print x.value.response d = send_plain_email(FROM_EMAIL, to_email, "Hello, this is a test.", {"From": from_address, "Subject": subject}) d.addBoth(cb) d.addCallbacks(lambda ign: os._exit(0), lambda ign: os._exit(1)) reactor.run()