def send_password_restore_ref(email, name, token): envelope = Envelope( from_addr=(u'*****@*****.**', u'PromTal'), to_addr=(email, name), subject=u'Восстановление пароля', # text_body=render_template('email/password_restore.html', token=token), text_body=render_template_string(restore_password, token=token), ) print(envelope) envelope.add_header("Content-Type", "text/html") gmail.send(envelope)
def send_news_notification(news_id, news_title): users = User.query.filter_by(news_notification=True).all() for user in users: envelope = Envelope( from_addr=(u'*****@*****.**', u'PromTal'), to_addr=(user.email, user.full_name), subject=u'Новая новость', # text_body=render_template('email/news_notification.html', id=news_id, title=news_title), text_body=render_template_string(news_notification, id=news_id, title=news_title), ) envelope.add_header("Content-Type", "text/html") gmail.send(envelope)
def send(self, links): self.connection = SMTP(port=self.port, host=self.host, tls=self.tls, login=self.login, password=self.password) envelope = Envelope(from_addr=(self.sender, u'Notification'), to_addr=(self.recipient), subject=self.subject, text_body=u"Nowy link:\n {}".format( "\n".join(links))) envelope.add_header('Date', email.utils.formatdate(localtime=True)) envelope.add_header('In-Reply-To', '*****@*****.**') try: self.connection.send(envelope) print('Email sent.') except Exception as e: print( 'Could not send email with links: {}'.format(','.join(links)), e)