Skip to content

Commit

Permalink
move send_test_email to email_utils.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schakrava committed Oct 3, 2015
1 parent 9c5941a commit cc1e16e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
20 changes: 1 addition & 19 deletions src/rockstor/storageadmin/views/email_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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

Expand Down
38 changes: 38 additions & 0 deletions src/rockstor/system/email_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Copyright (c) 2012-2015 RockStor, Inc. <http://rockstor.com>
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 <http://www.gnu.org/licenses/>.
"""

#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()

0 comments on commit cc1e16e

Please sign in to comment.