From cc1e16e4951588c5bb07ceb9fa56c8cdae75f9b6 Mon Sep 17 00:00:00 2001 From: Suman Chakravartula Date: Sat, 3 Oct 2015 14:19:28 -0700 Subject: [PATCH] move send_test_email to email_utils. This is a temporary hack because email_client.py view file was previously named email.py and because of lingering .pyc files, we run into import problems. I was unable to cleanup .pyc files as part of initrock or rpm spec file(oh, this only effects production style deployment not development) so the final approach is to amend the update_run to remove .pyc files(this will take effect in future) and move any code that imports email to a directory outside of views directory. with the update_run change in place, we can remove this temporary fix in a future update. --- .../storageadmin/views/email_client.py | 20 +--------- src/rockstor/system/email_util.py | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 src/rockstor/system/email_util.py diff --git a/src/rockstor/storageadmin/views/email_client.py b/src/rockstor/storageadmin/views/email_client.py index d9cf32c3d..13d89eb61 100644 --- a/src/rockstor/storageadmin/views/email_client.py +++ b/src/rockstor/storageadmin/views/email_client.py @@ -29,12 +29,7 @@ from tempfile import mkstemp from django.conf import settings from system.services import systemctl -import smtplib -from email.MIMEMultipart import MIMEMultipart -from email.MIMEBase import MIMEBase -from email.MIMEText import MIMEText -from email.Utils import formatdate -from email import Encoders +from system.email_util import send_test_email import logging logger = logging.getLogger(__name__) @@ -90,19 +85,6 @@ def update_postfix(smtp_server, revert=False): os.chmod(MAIN_CF, 0644) -def send_test_email(eco, subject): - msg = MIMEMultipart() - msg['From'] = eco.sender - msg['To'] = eco.receiver - msg['Date'] = formatdate(localtime=True) - msg['Subject'] = subject - - msg.attach(MIMEText(subject)) - smtp = smtplib.SMTP('localhost') - smtp.sendmail(eco.sender, eco.receiver, msg.as_string()) - smtp.close() - - class EmailClientView(rfc.GenericView): serializer_class = EmailClientSerializer diff --git a/src/rockstor/system/email_util.py b/src/rockstor/system/email_util.py new file mode 100644 index 000000000..a5d5cf6b5 --- /dev/null +++ b/src/rockstor/system/email_util.py @@ -0,0 +1,38 @@ +""" +Copyright (c) 2012-2015 RockStor, Inc. +This file is part of RockStor. + +RockStor is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; either version 2 of the License, +or (at your option) any later version. + +RockStor is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" + +#to be moved to views/email_client.py after an update or so. + +import smtplib +from email.MIMEMultipart import MIMEMultipart +from email.MIMEBase import MIMEBase +from email.MIMEText import MIMEText +from email.Utils import formatdate +from email import Encoders + +def send_test_email(eco, subject): + msg = MIMEMultipart() + msg['From'] = eco.sender + msg['To'] = eco.receiver + msg['Date'] = formatdate(localtime=True) + msg['Subject'] = subject + + msg.attach(MIMEText(subject)) + smtp = smtplib.SMTP('localhost') + smtp.sendmail(eco.sender, eco.receiver, msg.as_string()) + smtp.close()