def test_send(self): mail = Mailer(provider='gmail') subject = "Reset your password" data = {"user": {"fullname": "Brian Lee"}} body = mail.render_from_template(data=data, template_name='forgot_password') is_sent_mail = mail.send(subject=subject, body=body) assert is_sent_mail
def __send_email(self, to=None, BCC=None, html_body=None, title=None): message = Message(From=self.mailer_config['from'],To=to, BCC=BCC ) message.Subject = title if title is not None else 'EC2 Instance Alert' message.Html = html_body mailer_url_data = self.mailer_config['mailserver'].split(':') sender = Mailer(host=mailer_url_data[0], port=mailer_url_data[1], use_tls=True if self.mailer_config['use_tls'] == '1' else False, usr=self.mailer_config['auth_username'], pwd=self.mailer_config['auth_password']) sender.send(message)
async def contact(request): if request.method == 'GET': return html(template('contact.html').render()) else: name = request.form.get('name') email = request.form.get('email') subject = request.form.get('subject') message = request.form.get('message') mailer, url = Mailer(), None try: mailer.send_message(name, email, subject, message) url = app.url_for('index', message='Your message was sent!') except: url = app.url_for('index', message='Error: message failed to send') return redirect(url)
def send_email(self, to=None, BCC=None, html_body=None, title=None): # message = Message(From=self.mailer_config['from'],To=to, BCC=BCC, charset='utf-8' ) message = Message(From=self.mailer_config['from'],To=to, BCC=BCC ) message.Subject = title if title is not None else 'A Daily Report' message.Html = html_body mailer_url_data = self.mailer_config['mailserver'].split(':') sender = Mailer(host=mailer_url_data[0], port=mailer_url_data[1], use_tls=True if self.mailer_config['use_tls'] == '1' else False, usr=self.mailer_config['auth_username'], pwd=self.mailer_config['auth_password']) try: sender.send(message) except SMTPDataError as e: print "%s - %s" % (to, e)
def _callback(self, ch, method, properties, body): try: data = json.loads(body) email_message = EmailMessage(data["email"], data["subject"], data["html"]) Mailer().send_email(email_message) ch.basic_ack(delivery_tag=method.delivery_tag) except MailerException as e: self.logger.exception(e) ch.basic_nack(delivery_tag=method.delivery_tag, requeue=False)
def test_init_mailer_failure(): config.api_key = None with pytest.raises(ApiKeyError): Mailer()
from payment_service.payment_service import PaymentService import pytest from mock import call, patch, Mock from nameko.events import event_handler from nameko.testing.utils import get_extension from nameko.standalone.events import event_dispatcher from nameko.testing.services import entrypoint_waiter import requests import requests_mock import config mailer = Mailer() @pytest.fixture def mock_event(): payload = { 'client': { 'name': 'zoe', 'email': '*****@*****.**' }, 'payee': { 'name': 'Phil', 'email': '*****@*****.**' }, 'payment': { 'amount': 10000,