diff options
| author | LV-426 <lv-426@taproot.org.il> | 2015-04-20 15:08:35 +0300 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2015-04-20 18:46:13 +0300 |
| commit | 03c367a5b934299dec687e37570b8612f225e60b (patch) | |
| tree | 85a03f63d221e8805f8ba647b5e99da86f02e865 /src/server/rz_mail.py | |
| parent | 9badd356140a9e4f21dc508509f7276737c5eb6f (diff) | |
rz_mail: rename send_email_message -> send_email__flask_ctx + doc
Diffstat (limited to 'src/server/rz_mail.py')
| -rw-r--r-- | src/server/rz_mail.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/server/rz_mail.py b/src/server/rz_mail.py index 82c71d8f..38d894c0 100644 --- a/src/server/rz_mail.py +++ b/src/server/rz_mail.py @@ -11,13 +11,16 @@ import smtplib log = logging.getLogger('rhizi') -def send_email_message(recipients, subject, body, attachments=[]): +def send_email__flask_ctx(recipients, subject, body, attachments=[]): + """ + Flask context dependent email sending utility + """ send_from = current_app.rz_config.mail_default_sender mta_host = current_app.rz_config.mta_host mta_port = current_app.rz_config.mta_port - send_message_helper(mta_host, + send_email(mta_host, mta_port, send_from=send_from, recipients=recipients, @@ -27,12 +30,11 @@ def send_email_message(recipients, subject, body, attachments=[]): log.info('email sent: recipients: %s: subject: %s, attachment-count: %d' % (recipients, subject, len(attachments))) -def send_message_helper(mta_host, mta_port, send_from, recipients, subject, attachments, body): +def send_email(mta_host, mta_port, send_from, recipients, subject, attachments, body): """ - attachments is a list of tuples (filename, mimetype, data) + Note: to allow for easy testing this function should not depend on any flask app/request context - note: helper exists for ease of testing, since it doesn't use flask only - python batteries-included packages + @param attachments: is a list of tuples (filename, mimetype, data) """ assert isinstance(recipients, list) @@ -58,5 +60,5 @@ def send_message_helper(mta_host, mta_port, send_from, recipients, subject, atta if __name__ == '__main__': # FIXME - move to actual test suite - send_message_helper('localhost', 'alon@localhost', ['alon@localhost'], 'test subject', [ + send_email('localhost', 'alon@localhost', ['alon@localhost'], 'test subject', [ ('diary.txt', 'text/plain', "bla bla bla yeah that's right bla")], 'this is it pal') |
