Sindbad~EG File Manager

Current Path : /home/numerotech/conf-badge.numerotech.com/conference_badge/core/library/
Upload File :
Current File : //home/numerotech/conf-badge.numerotech.com/conference_badge/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 sendMail(subject,html,to,conf):
		# to = "ganesan@numerotec.com"  # for test use
		# MANDRILL_API_KEY='MAoeFJshVAG4-xTyPpTgUg'
		if to:
			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['from_email'],
			"headers" :{"Reply-To": conf['reply_to']} ,'to' : [{'email':to,'name':to,'type':'to'},{'email':conf['backup_email'],'name':to,'type':'cc'}] }

			result = mandrill_client.messages.send(message = message,send_async=True)
			return ('success')

		else:
			return ('Email Id is Blank')
		
	# The below function updated by Ganesan 2022-11-05 13:00:00	
	def KcReportMail(subject,html,to,from_name):
		# MANDRILL_API_KEY='MAoeFJshVAG4-xTyPpTgUg'
		MANDRILL_API_KEY='md-WHhIRdtiJJHa7wD0_WY6pQ' # IP ADDRESS ENABLED
		mandrill_client = mandrill.Mandrill(MANDRILL_API_KEY)
 
		message = {'subject' : subject, 'recipients':to,'from_name': from_name,
		'html': html, 'from_email' : 'support@numerotec.com',
		"headers" :{"Reply-To": "support@numerotec.com"} ,'to' : [{'email':to,'name':to,'type':'to'},{'email':'ganesan@numerotec.com','name':to,'type':'to'}] }
 
		result = mandrill_client.messages.send(message = message,send_async=True)
		return ('success')

	def FcReportMail(subject,html,to):
		# MANDRILL_API_KEY='MAoeFJshVAG4-xTyPpTgUg'
		MANDRILL_API_KEY='3rql7lHFpPcoHnNAWYQTFQ' # IP ADDRESS ENABLED
		mandrill_client = mandrill.Mandrill(MANDRILL_API_KEY)
 
		message = {'subject' : subject, 'recipients':to,'from_name': 'Food counter report',
		'html': html, 'from_email' : 'support@numerotec.com',
		"headers" :{"Reply-To": "support@numerotec.com"} ,'to' : [{'email':to,'name':to,'type':'to'}] }
 
		result = mandrill_client.messages.send(message = message,send_async=True)
		return ('success')	
		
	def allconfcountsendMail(subject,html,to):
		if to:
			MANDRILL_API_KEY='3rql7lHFpPcoHnNAWYQTFQ'
			mandrill_client = mandrill.Mandrill(MANDRILL_API_KEY)
			message = {'subject' : subject, 'recipients':to,'from_name': 'Delegate Registration',
			'html': html, 'from_email' : "support@numerotec.com",
			"headers" :{"Reply-To":"support@numerotec.com"} ,'to' : [{'email':to,'name':to,'type':'to'}] }
			try:
				result = mandrill_client.messages.send(message = message,send_async=True)
			except:
				print("error in mandrill")
			return ('success')

		else:
			return ('Email Id is Blank')	
	
	
	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 "Mail not send"
			
	def SendMailDuplicate(subject,html,to,conf):
		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')


# download function for xl file,by Aravinth
	def SendReportMail(subject,html,to,attachments,from_name):
		MANDRILL_API_KEY='3rql7lHFpPcoHnNAWYQTFQ' # IP ADDRESS ENABLED
		mandrill_client = mandrill.Mandrill(MANDRILL_API_KEY)
		 
		message = {'subject' : subject, 'recipients':to,'from_name': from_name,
		'html': html, 'from_email' : 'support@numerotec.com',
		"headers" :{"Reply-To": "support@numerotec.com"} ,'to' : [{'email':to,'name':to,'type':'to'}]
		,
		"attachments": [
		{
		"type": "application/xlsx",
		"name": subject + ".xls",
		"content": attachments
		}],
		}
 
		result = mandrill_client.messages.send(message = message,send_async=True)
		return ('success')
		
	def SignupReportMail(subject,html,to):
		# MANDRILL_API_KEY='MAoeFJshVAG4-xTyPpTgUg'
		MANDRILL_API_KEY='3rql7lHFpPcoHnNAWYQTFQ' # IP ADDRESS ENABLED
		mandrill_client = mandrill.Mandrill(MANDRILL_API_KEY)
 
		message = {'subject' : subject, 'recipients':to,'from_name': 'BADGE DISBURSAL REPORT',
		'html': html, 'from_email' : "support@numerotec.com",
		"headers" :{"Reply-To": ""} ,'to' : [{'email':to,'name':to,'type':'to'},{'email':'ganesan@numerotec.com','name':to,'type':'to'}] }
 
		result = mandrill_client.messages.send(message = message,send_async=True)
		return ('success')
		
		
	def MandrillMailFunciton(subject,html,to,from_name):
		MANDRILL_API_KEY='3rql7lHFpPcoHnNAWYQTFQ' # IP ADDRESS ENABLED
		mandrill_client = mandrill.Mandrill(MANDRILL_API_KEY)
 
		message = {'subject' : subject, 'recipients':to,'from_name': from_name,
		'html': html, 'from_email' : 'support@numerotec.com',
		"headers" :{"Reply-To": "support@numerotec.com"} ,'to' : [{'email':to,'name':to,'type':'to'}] }
 
		result = mandrill_client.messages.send(message = message,send_async=True)
		return ('success')	

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