diff options
| author | LV-426 <lv-426@taproot.org.il> | 2015-04-20 15:09:13 +0300 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2015-04-20 18:46:13 +0300 |
| commit | fdb734b9b8201bd8a07a118a4bebaacf7abb18e6 (patch) | |
| tree | cb755c94eecee58704654747927a5cfc17d4b1a1 /src | |
| parent | 03c367a5b934299dec687e37570b8612f225e60b (diff) | |
rz_mail: reorder, cleanup misplaced test
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/rz_mail.py | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/src/server/rz_mail.py b/src/server/rz_mail.py index 38d894c0..7680dd38 100644 --- a/src/server/rz_mail.py +++ b/src/server/rz_mail.py @@ -11,25 +11,6 @@ import smtplib log = logging.getLogger('rhizi') -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_email(mta_host, - mta_port, - send_from=send_from, - recipients=recipients, - subject=subject, - attachments=attachments, - body=body) - - log.info('email sent: recipients: %s: subject: %s, attachment-count: %d' % (recipients, subject, len(attachments))) - def send_email(mta_host, mta_port, send_from, recipients, subject, attachments, body): """ Note: to allow for easy testing this function should not depend on any flask app/request context @@ -58,7 +39,21 @@ def send_email(mta_host, mta_port, send_from, recipients, subject, attachments, smtp.sendmail(send_from, recipients, msg.as_string()) smtp.close() -if __name__ == '__main__': - # FIXME - move to actual test suite - 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') +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_email(mta_host, + mta_port, + send_from=send_from, + recipients=recipients, + subject=subject, + attachments=attachments, + body=body) + + log.info('email sent: recipients: %s: subject: %s, attachment-count: %d' % (recipients, subject, len(attachments))) |
