Beispiel #1
0
    def test_recipients_properly_initialized(self):

        msg = Message(subject="subject")
        self.assertEqual(msg.recipients, [])

        msg2 = Message(subject="subject")
        msg2.add_recipient("*****@*****.**")
        self.assertEqual(len(msg2.recipients), 1)
Beispiel #2
0
    def test_sender_as_tuple(self):

        msg = Message(subject="testing",
                      sender=("tester", "*****@*****.**"),
                      body="test")

        msg_str = msg.dump()
        self.assertTrue("From: tester <*****@*****.**>" in str(msg_str))
Beispiel #3
0
    def test_send_without_sender(self):

        del self.app.config['DEFAULT_MAIL_SENDER']

        msg = Message(subject="testing",
                      recipients=["*****@*****.**"],
                      body="testing")

        self.assertRaises(AssertionError, self.mail.send, msg)
Beispiel #4
0
    def test_cc(self):

        msg = Message(subject="testing",
                      recipients=["*****@*****.**"],
                      body="testing",
                      cc=["*****@*****.**"])

        msg_str = msg.dump()
        self.assertTrue("Cc: [email protected]" in str(msg_str))
Beispiel #5
0
    def test_reply_to(self):

        msg = Message(subject="testing",
                      recipients=["*****@*****.**"],
                      sender="spammer <*****@*****.**>",
                      reply_to="somebody <*****@*****.**>",
                      body="testing")

        msg_str = msg.dump()
        self.assertTrue(
            "Reply-To: somebody <*****@*****.**>" in str(msg_str))
Beispiel #6
0
    def send_email_message(self, recipient, subject, html_message,
                           text_message, sender_email, sender_name):
        """ Send email message via Flask-Sendmail.

        Args:
            recipient: Email address or tuple of (Name, Email-address).
            subject: Subject line.
            html_message: The message body in HTML.
            text_message: The message body in plain text.
        """

        if not current_app.testing:  # pragma: no cover

            # Prepare email message
            from flask_sendmail import Message
            message = Message(subject,
                              recipients=[recipient],
                              html=html_message,
                              body=text_message)

            # Send email message
            self.mail.send(message)
Beispiel #7
0
def send_mail(to, sender, cc=None, subject=None, message=None):
    #in order to get this to work, had to change the libraries as follows:
    #/home/admin/wagsv_python/venv/lib/python3.5/site-packages/flask_sendmail/connection.py[23]
    #   sm.stdin.write(str.encode(message.dump()))
    #/usr/lib/python3.5/email/mime/text.py[17]
    #   def __init__(self, _text, _subtype='plain', _charset='utf-8'):
    to = force_list(to)
    msg = Message(subject)
    msg.sender = sender
    msg.recipients = to
    msg.cc = force_list(cc)
    msg.body = '\n'.join(force_list(message))
    app = current_app._get_current_object()
    if config.get('send_mail'):
        #send_async_email(app, msg)
        mail.send(msg)
    else:
        out = [
            'Email:', 'from: ' + sender, 'to: ' + ', '.join(to),
            'subject: ' + subject, 'message:'
        ]
        print('\n'.join(out + force_list(message)))
Beispiel #8
0
    def test_send_without_body(self):

        msg = Message(subject="testing", recipients=["*****@*****.**"])

        self.assertRaises(AssertionError, self.mail.send, msg)
Beispiel #9
0
    def test_send_without_recipients(self):

        msg = Message(subject="testing", recipients=[], body="testing")

        self.assertRaises(AssertionError, self.mail.send, msg)
Beispiel #10
0
    def test_add_recipient(self):

        msg = Message("testing")
        msg.add_recipient("*****@*****.**")

        self.assertEqual(msg.recipients, ["*****@*****.**"])
Beispiel #11
0
    def test_initialize(self):

        msg = Message(subject="subject", recipients=['*****@*****.**'])

        self.assertEqual(msg.sender, "*****@*****.**")
        self.assertEqual(msg.recipients, ['*****@*****.**'])