Esempio n. 1
0
 def SendMail(self,
              sender='*****@*****.**',
              recipient="*****@*****.**",
              subject="test mail",
              body="Sample Body"):
     try:
         #pdb.set_trace()
         recipient = buildList(recipient)
         print '>>> Start Sending mail.....'
         headers = [
             "From: " + sender, "Subject: " + subject,
             "To: " + str(recipient), "MIME-Version: 1.0",
             "Content-Type: text/html"
         ]
         headers = "\r\n".join(headers)
         #pdb.set_trace()
         session = smtplib.SMTP(self.SMTP_SERVER, self.SMTP_PORT)
         session.ehlo()
         session.starttls()
         session.ehlo()
         session.login(self.UNAME, self.PASSWD)
         session.sendmail(sender, recipient, headers + "\r\n\r\n" + body)
         session.quit()
         print '>>> Email Send Successfully to', recipient
         return {
             'status': 'success',
             'msg': 'mail sent to  ' + str(recipient)
         }
     except Exception, e:
         print '>>> ERROR:SendMail ', e
         Log(e)
         return {'status': 'error', 'msg': str(e)}
Esempio n. 2
0
 def SendMail(
     self,
     sender="*****@*****.**",
     recipient="*****@*****.**",
     subject="test mail",
     body="Sample Body",
 ):
     try:
         # pdb.set_trace()
         recipient = buildList(recipient)
         print ">>> Start Sending mail....."
         headers = [
             "From: " + sender,
             "Subject: " + subject,
             "To: " + str(recipient),
             "MIME-Version: 1.0",
             "Content-Type: text/html",
         ]
         headers = "\r\n".join(headers)
         # pdb.set_trace()
         session = smtplib.SMTP(self.SMTP_SERVER, self.SMTP_PORT)
         session.ehlo()
         session.starttls()
         session.ehlo()
         session.login(self.UNAME, self.PASSWD)
         session.sendmail(sender, recipient, headers + "\r\n\r\n" + body)
         session.quit()
         print ">>> Email Send Successfully to", recipient
         return {"status": "success", "msg": "mail sent to  " + str(recipient)}
     except Exception, e:
         print ">>> ERROR:SendMail ", e
         Log(e)
         return {"status": "error", "msg": str(e)}
Esempio n. 3
0
def ajax_send_email(request): # TODO SUPPORT JSON WILL TAKJE CARE BY POST>?>>>>
    res= {}
    #pdb.set_trace()
    try:
        if request.method == 'POST' :# in case of POST, We have Json Request..         
            data = json.loads(request.body)
            recipient = data['recipient']
            subject = data['subject']
            template = data['template']
            data = data['data']
        elif request.method == 'GET':
            recipient = request.GET['recipient']
            subject = request.GET['subject']
            template = request.GET['template']
            data = RequestGetToDict(request.GET)
            data['time'] = time.ctime()    
        else:
            res ={'status':'error','msg':'Operation Not supported '};
            return HttpResponse(decodeUnicodeDirectory(res), content_type = 'application/json')  
        recipient_list= utils.buildList(recipient)
        m = MailEngine.MailEngine()
        sender = '*****@*****.**'
        res =  m.SendMailUsingTemplate(sender,recipient_list,subject,template,data)
    except Exception,e:
        d = Log(e)
        res ={'status':'error','fname':str(e),'stack':d};