summaryrefslogtreecommitdiff
path: root/sbhs_server/helpers/mailer.py
blob: 2ba901ee5cf6ac771ce65a97046f8e970afe4dd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from sbhs_server import settings
import smtplib

def email(to, subject, message):
    """ Utility function to send the e-mail using SMTP.
    """
    smtpserver = smtplib.SMTP()
    smtpserver.connect(settings.EMAIL_HOST, settings.EMAIL_PORT)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo()
    smtpserver.esmtp_features['auth']='LOGIN DIGEST-MD5 PLAIN'
    smtpserver.login(settings.EMAIL_HOST_USER, settings.EMAIL_HOST_PASSWORD)

    header = 'To: ' + to + '\n' + 'From: ' + settings.EMAIL_HOST_USER + '@iitb.ac.in\n' + 'Subject: ' + subject +' \n'
    msg = header + '\n' + message + '\n\n'
    #smtpserver.sendmail(settings.EMAIL_HOST_USER + '@iitb.ac.in', to, msg)
    smtpserver.sendmail(settings.EMAIL_HOST_USER , to, msg)
    smtpserver.close()