Sindbad~EG File Manager

Current Path : /home/numerotech/workshops.numerotech.com/common_workshop_reg/core/library/
Upload File :
Current File : //home/numerotech/workshops.numerotech.com/common_workshop_reg/core/library/email.py

from flask import request, url_for,flash, render_template
from core import app
from flask import url_for
from datetime import datetime, date, time, timedelta
import requests,mandrill,json

from core.library.Mandrill import Mandrill
from core.library.Mailgun import Mailgun

class EMAIL:
	def MailTemplateSendMail(subject,html,to,mailData,conf):
		if conf:
			if conf['driver'] == 'mailgun':
					# pass
				data =  Mailgun.sendMail(subject,html,to,mailData,conf)
				return None
			elif conf['driver'] == 'mandrill':
				# pass
				data = Mandrill.sendMail(subject,html,to,mailData,conf)
				return data
			else:
				return "Please check mail configuration setting"
		else:
			return redirect (url_for('user.Home'))
			
	def MailTemplateSendMail_v2(subject,html,to_mail,bcc_mail,mailData,conf):
		if conf:
			if conf['driver'] == 'mailgun':
					# pass
				data =  Mailgun.sendMail_v2(subject,html,to_mail,bcc_mail,mailData,conf)
				return None
			elif conf['driver'] == 'mandrill':
				# pass
				data = Mandrill.sendMail(subject,html,to_mail,bcc_mail,mailData,conf)
				return data
			else:
				return "Please check mail configuration setting"
		else:
			return redirect (url_for('user.Home'))		

	
	def sendMail(subject,html,to,conf):
		# MANDRILL_API_KEY='MAoeFJshVAG4-xTyPpTgUg'
		if to:
			MANDRILL_API_KEY='3rql7lHFpPcoHnNAWYQTFQ'
			# MANDRILL_API_KEY='md-WHhIRdtiJJHa7wD0_WY6pQ' # IP ADDRESS ENABLED
			mandrill_client = mandrill.Mandrill(MANDRILL_API_KEY)

			message = {'subject' : subject, 'recipients':to,'from_name': conf['conf_title'],
			'html': html, 'from_email' : conf['e_from_email'],
			"headers" :{"Reply-To": conf['e_reply_to']} ,'to' : [{'email':to,'name':to,'type':'to'},{'email':conf['e_backup_emails'],'name':to,'type':'cc'}] }

# 			result = mandrill_client.messages.send(message = message,send_async=True)
			try:
				result = mandrill_client.messages.send(message = message,send_async=True)
				if result :
					result[0]["msg_id"] = result[0]["_id"]
					result[0]["api_key"] = MANDRILL_API_KEY
					result[0]["app_type"] = "DELEGATE"
					result[0]["subject"] = subject
					data_1 = json.dumps(result[0],default=str)
					return data_1
				
			except Exception as e:
				print(str(e))
				print("error in mandrill")
			
			return ('success')

		else:
			return ('Email Id is Blank')
			
			
	def allconfcountsendMail(subject,html,to):
		if to:
			from_mail_name 	= 'NumeroTec Support'
			from_mail_id 	= 'support@numerotec.com'
			reply_mail_id 	= 'support@numerotec.com'
			c_srt_key       = 'key-e13725db7c3a95b679911c038b490db1'
			c_domain        = 'numerotech.com'
			bcc             = []			
			# return "mail sent successful"
			cc      		= []
			url  			= 'https://api.mailgun.net/v3/'+str(c_domain)+'/messages'
			auth 			= ('api',c_srt_key)
			data 			= {
								'from'   : from_mail_name+'<'+from_mail_id+'>',
								'to'     : to,
								'cc'     : cc,
								'bcc'    : bcc,
								'subject': subject,
								'html'   : html
			}
			data['h:Reply-To'] = reply_mail_id
			res  = requests.post(url, auth=auth, data=data)
			return ("mail sent successful.")
		else:
			return ('Email Id is Blank')
			
			
	def sendMailResetPassword(subject,html,to,conf):
		cc      = []
		bcc     = []
		url  = 'https://api.mailgun.net/v3/mg.numerotec.com/messages'
		auth = ('api', 'key-e13725db7c3a95b679911c038b490db1')
		# society_data = Auth.getSociety(society_id)
		data = {
		'from'   : conf['conf_name']+'<'+conf['e_from_email']+'>',
		'to'     : to,
		'cc'     : cc,
		'bcc'    : bcc,
		'subject': subject,
		'html'   : html
		}
		
		data['h:Reply-To']= conf['e_reply_to'] 
		res  = requests.post(url, auth=auth, data=data)
		return "mail sent successful."		

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists