def verify_mail(**kwargs): message = Message(html=render_template('email/verify_email.html', hash=kwargs['hash'], uid=kwargs['uid']), subject="Подтверждение адреса электронной почты", mail_from=("КУДАБЫ", "*****@*****.**")) r = message.send(to=(kwargs['email']))
def welcome_mail(addr): message = Message(html=render_template( 'email/welcome.html', header="Привет!", text="Добро пожаловать на КУДАБЫ.РУ"), subject="Добро пожаловать!", mail_from=("КУДАБЫ", "*****@*****.**")) r = message.send(to=(addr))
def test_flask_send_dummy(): # Send via dummy backend app = Flask(__name__) app.config.update({'EMAIL_BACKEND': 'flask_emails.backends.DummyBackend'}) from flask.ext.emails import Message # Message.init_app(app) ctx = app.test_request_context() ctx.push() m = Message(**SAMPLE_MESSAGE) m.send(smtp={'timeout': 1})
def test_flask_send_real(): # Send via real backend app = Flask(__name__) app.config.update({'EMAIL_HOST': 'mx.yandex.ru', 'EMAIL_FAIL_SILENTLY': False}) from flask.ext.emails import Message ctx = app.test_request_context() ctx.push() # Message.init_app(app) m = Message(**SAMPLE_MESSAGE) r = m.send() assert r.status_code == 250
def test_flask_send_real(): # Send via real backend app = Flask(__name__) app.config.update({ 'EMAIL_HOST': 'mx.yandex.ru', 'EMAIL_FAIL_SILENTLY': False }) from flask.ext.emails import Message ctx = app.test_request_context() ctx.push() # Message.init_app(app) m = Message(**SAMPLE_MESSAGE) r = m.send() assert r.status_code == 250
def test_flask_message(): app = Flask(__name__) app.config.update({'EMAIL_DEFAULT_FROM': 'John Brawn <*****@*****.**>'}) ctx = app.test_request_context() ctx.push() from flask.ext.emails import Message m = Message(html='...') assert m.mail_from == ('John Brawn', '*****@*****.**')
def send_password_reset_code(self): """Create a password reset code""" reset_token = ''.join( random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(RESET_TOKEN_LEN)) self._data['_reset_token'] = reset_token self._set_modified(True) self.save() logger.info("Password reset requested for (%s) : %s", self.email, reset_token) with (Path(app.config.ASSETS_PATH) / 'html/recover.html').open() as html, \ (Path(app.config.ASSETS_PATH) / 'txt/recover.txt').open() as txt, \ (Path(app.config.ASSETS_PATH) / 'img/epmanage.png').open('rb') as logo: msg = Message( html=T(html.read()), text=T(txt.read()), subject="Account recovery for {}".format(self.email), mail_from=("EPManage", app.config.EMAIL_ADDRESS), message_id=make_msgid(domain=app.config.EMAIL_DOMAIN)) msg.attach(filename="epmanage.png", content_disposition="inline", data=logo) msg.send(to=self.email, render={ 'USER_EMAIL': self.email, 'URL_TO_RESET': "{}/{}".format(app.config.RECOVERY_URL, reset_token) }) return True
def invite(data: dict): """ Create a Client object ready for registration :return: the registration_token to be used for registration """ max_agents = data.pop('max_agents') if max_agents > app.config.INVITE_MAX_AGENTS: raise AuthException("Please set a maximum of {} agents".format(app.config.INVITE_MAX_AGENTS)) max_users = data.pop('max_users') if max_users > app.config.INVITE_MAX_USERS: raise AuthException("Please set a maximum of {} users".format(app.config.INVITE_MAX_USERS)) client = epmanage.lib.client.Client() client.invitation_email = data.pop('email') client.max_agents = max_agents client.max_users = max_users client.token = ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.digits) for _ in range(32)) client.registration_token = ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.digits) for _ in range(20)) client.database_settings = dict( DBNAME='{}_corp'.format(client.token) ) client.save() client.insert_default_data() sender = AuthController.get_current_identity().get_user() user_name = "{} {}".format(sender.firstname, sender.lastname) user_email = sender.email with (Path(app.config.ASSETS_PATH) / 'html/invite.html').open() as html, \ (Path(app.config.ASSETS_PATH) / 'txt/invite.txt').open() as txt, \ (Path(app.config.ASSETS_PATH) / 'img/rocket.png').open('rb') as rocket, \ (Path(app.config.ASSETS_PATH) / 'img/epmanage.png').open('rb') as logo: msg = Message( html=T(html.read()), text=T(txt.read()), subject="Invitation to the EPManage", mail_from=(user_name, user_email), message_id=make_msgid(domain=app.config.EMAIL_DOMAIN)) msg.attach(filename="rocket.png", content_disposition="inline", data=rocket) msg.attach(filename="epmanage.png", content_disposition="inline", data=logo) msg.send(to=client.invitation_email, render={ 'USER_NAME': user_name, 'USER_EMAIL': user_email, 'URL_TO_JOIN': "{}/{}".format(app.config.REGISTRATION_URL, client.registration_token) }) return client.registration_token
def welcome_mail(): message = Message(html=render_template('email/welcome.html', header="Привет!", text="Добро пожаловать на КУДАБЫ.РУ"), subject="Добро пожаловать!", mail_from=("КУДАБЫ", "*****@*****.**")) r = message.send(to=("*****@*****.**"))
def verify_mail(**kwargs): message = Message(html=render_template('email/verify_email.html', hash= kwargs['hash'], uid= kwargs['uid']), subject="Подтверждение адреса электронной почты", mail_from=("КУДАБЫ", "*****@*****.**")) r = message.send(to=(kwargs['email']))