Skip to content

Commit

Permalink
Moved to Django Emailer
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed ElKalioby committed Sep 18, 2017
1 parent 0fb3955 commit 1ef4057
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 43 deletions.
14 changes: 6 additions & 8 deletions webapp/autoDeploy/autoDeploy/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,9 @@

LOGIN_URL=BASE_URL+"accounts/login"

SMTP= {
'HOST': 'smtp.gmail.com',
'PORT': '587',
'USERNAME': '',
'PASSWORD': '',
'FROM':'Auto Deploy'

}
EMAIL_HOST= 'smtp.gmail.com'
EMAIL_PORT= 587
EMAIL_HOST_USER= ''
EMAIL_HOST_PASSWORD=''
EMAIL_USE_TLS=True
EMAIL_FROM="AutoDeploy"
48 changes: 13 additions & 35 deletions webapp/autoDeploy/autodeploy/Common.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,17 @@
__author__ = 'mohamed'

def send(to,subject,body,fromUser=None,cc="",bcc="",):

from django.conf import settings
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
From=fromUser
if fromUser==None:
From="%s<%s>"%(settings.SMTP["FROM"],settings.SMTP["USERNAME"])
try:
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = From
#msg['To'] = to one email
msg['Cc']= cc
if type(to)==type([]):
msg['To'] = ', '.join( to) #More than one email
else:
msg['To'] = to
html = body
part2 = MIMEText(html, 'html')
msg.attach(part2)
server = smtplib.SMTP(settings.SMTP["HOST"],settings.SMTP["PORT"])
server.ehlo()
server.starttls()
server.login(settings.SMTP["USERNAME"], settings.SMTP["PASSWORD"])
for t in to.split(";"):
server.sendmail(From, t, msg.as_string())
if cc!="":
server.sendmail(From, cc, msg.as_string())
if bcc!="":
server.sendmail(From, bcc, msg.as_string())
server.quit()
return True

except Exception as exp:
return False
from django.core.mail import EmailMessage
From = "%s<%s>" % (fromUser, settings.EMAIL_HOST_USER)
if fromUser == None:
From = "%s<%s>" % (settings.EMAIL_FROM, settings.EMAIL_HOST_USER)
if type(to) != type([]):
to = [to]
email = EmailMessage(
subject,
body,
From,
to, cc=cc, bcc=bcc)
email.content_subtype = "html"
return email.send(True)

0 comments on commit 1ef4057

Please sign in to comment.