def send_email_msg(from_email, to_email, msg_subject, msg_purpose, msg_text, msg_html): if not has_existing_message(to_email, msg_purpose): try: add_to_message_log(to_email, msg_purpose, msg_text, msg_subject, msg_html) try: categories = [msg_purpose] if 'localhost' in constants.HOST or 'pagekite' in constants.HOST: sgw.send_message( sender=from_email, recipients=[sgw.Email(constants.DEV_EMAIL, constants.DEV_EMAIL)], subject='DEV: ' + msg_subject, body_text=msg_text, body_html=msg_html, categories=categories) else: sgw.send_message( sender=from_email, recipients=[sgw.Email(to_email, to_email)], subject=msg_subject, body_text=msg_text, body_html=msg_html, bccs=BCC_RECIPIENTS, categories=categories) except Exception as e: sgw.notify_admins("Unable to send email message for " + to_email + " because \n\n" + str(e)) except Exception as e: sgw.notify_admins("Unable to write to message log for " + to_email + " because \n\n" + str(e))
def send_email_msg(from_email, to_email, msg_subject, msg_category, msg_text, msg_html): try: categories = [msg_category] if 'localhost' in constants.HOST or 'pagekite' in constants.HOST: sgw.send_message(sender=from_email, recipients=[ sgw.Email(constants.DEV_EMAIL, constants.DEV_EMAIL) ], subject='DEV: ' + msg_subject, body_text=msg_text, body_html=msg_html, categories=categories) else: sgw.send_message(sender=from_email, recipients=[to_email], subject=msg_subject, body_text=msg_text, body_html=msg_html, bccs=BCC_RECIPIENTS, categories=categories) except Exception as e: sgw.notify_admins("Unable to send email message to " + to_email.email + " because \n\n" + str(e))
def send_welcome(email): if not re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", email): return jsonify("Please enter a valid email address") try: me = db_models.EmailList() me.email = email me.unsubscribed = False db.session.add(me) db.session.commit() except: return jsonify('You are already signed up!') to_email = sgw.Email(email, email) email_types.send_email_type('welcome', DEFAULT_SENDER, to_email) return jsonify('Thanks for signing up!')
import re from flask import jsonify, flash, redirect from config import universal from database import db, db_common, db_models from logic.emails import email_types from util import sendgrid_wrapper as sgw from tools import db_utils from flask_babel import gettext, Babel, Locale DEFAULT_SENDER = sgw.Email(universal.CONTACT_EMAIL, universal.BUSINESS_NAME) def send_welcome(email): if not re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", email): return gettext('Please enter a valid email address') try: me = db_models.EmailList() me.email = email me.unsubscribed = False db.session.add(me) db.session.commit() except: return gettext('You are already signed up!') email_types.send_email_type('welcome', DEFAULT_SENDER, email)
from config import universal, constants from database import db, db_models from flask import render_template from util import sendgrid_wrapper as sgw DEFAULT_SENDER = sgw.Email(universal.CONTACT_EMAIL, universal.BUSINESS_NAME) BCC_RECIPIENTS = [sgw.Email('*****@*****.**', 'Founders')] EMAILS = { 'welcome': { 'subject': 'Welcome to Origin Protocol' }, 'presale': { 'subject': 'Thanks for your interest in Origin!' }, 'demo_dapp_announcement': { 'subject': 'Origin Demo DApp is now live on testnet' }, 'build_on_origin': { 'subject': 'Thanks for your interest in Origin!' }, } def send_email_type(email_type, from_email, to_email): msg_subject = EMAILS.get(email_type).get('subject') msg_text = render_template('email/%s.txt' % email_type, universal=universal, to_email=to_email) msg_html = render_template('email/%s.html' % email_type, universal=universal, to_email=to_email) send_email_msg(from_email, to_email, msg_subject, email_type, msg_text, msg_html)
from config import constants from util import sendgrid_wrapper as sgw BCC_RECIPIENTS = [sgw.Email('*****@*****.**', 'Founders')] def send_email_msg(from_email, to_email, msg_subject, msg_category, msg_text, msg_html): try: categories = [msg_category] if 'localhost' in constants.HOST or 'pagekite' in constants.HOST: sgw.send_message(sender=from_email, recipients=[ sgw.Email(constants.DEV_EMAIL, constants.DEV_EMAIL) ], subject='DEV: ' + msg_subject, body_text=msg_text, body_html=msg_html, categories=categories) else: sgw.send_message(sender=from_email, recipients=[to_email], subject=msg_subject, body_text=msg_text, body_html=msg_html, bccs=BCC_RECIPIENTS, categories=categories)