|
|
@@ -96,6 +96,86 @@ class Emailer():
|
|
|
server.quit()
|
|
|
self.logger.info("Correo electrónico enviado con éxito a la dirección {0}".format(to_address))
|
|
|
|
|
|
+ def send_success_email_by_api(self, from_address, to_address, alert_message, subject, type=None, report_count=0):
|
|
|
+
|
|
|
+ import requests
|
|
|
+
|
|
|
+ message_template = self.read_template(os.path.join(config.TEMPLATES_PATH,'success-message-inline.html'))
|
|
|
+
|
|
|
+ self.logger.info("Preparando para enviar correo electrónico")
|
|
|
+ head_color = "#6bab01"
|
|
|
+ message = message_template.substitute(fecha=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
+ alert_message=alert_message,
|
|
|
+ cuenta_reportes=report_count,
|
|
|
+ head_color=head_color)
|
|
|
+
|
|
|
+ url = config.SB_URL
|
|
|
+ api_key = config.SB_API_KEY
|
|
|
+ self.logger.debug("url: "+ url)
|
|
|
+ self.logger.debug("key: "+ api_key)
|
|
|
+
|
|
|
+ payload = {
|
|
|
+ "sender":
|
|
|
+ {
|
|
|
+ "email":from_address,
|
|
|
+ "name":"BOT DESCARGA DF"
|
|
|
+ },
|
|
|
+ "to":[{"email":to_address}],
|
|
|
+ "htmlContent":message,
|
|
|
+ "subject":subject
|
|
|
+ }
|
|
|
+ headers = {
|
|
|
+ 'accept': "application/json",
|
|
|
+ 'content-type': "application/json",
|
|
|
+ 'api-key': api_key
|
|
|
+ }
|
|
|
+
|
|
|
+ self.logger.debug("Enviando correo electrónico")
|
|
|
+
|
|
|
+ response = requests.request("POST", url, json=payload, headers=headers, verify=False)
|
|
|
+
|
|
|
+ self.logger.debug("Correo Electrónico enviado")
|
|
|
+ self.logger.info("Correo electrónico enviado con éxito a la dirección {0}".format(to_address))
|
|
|
+
|
|
|
+ def send_warning_email_by_api(self, from_address, to_address, alert_message, subject):
|
|
|
+
|
|
|
+ import requests
|
|
|
+
|
|
|
+ message_template = self.read_template(os.path.join(config.TEMPLATES_PATH, 'warning-message-inline.html'))
|
|
|
+
|
|
|
+ self.logger.info("Preparando para enviar correo electrónico")
|
|
|
+ head_color = "#ffaa00"
|
|
|
+ message = message_template.substitute(fecha=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
+ alert_message=alert_message,
|
|
|
+ head_color=head_color)
|
|
|
+
|
|
|
+ url = config.SB_URL
|
|
|
+ api_key = config.SB_API_KEY
|
|
|
+ self.logger.debug("url: "+ url)
|
|
|
+ self.logger.debug("key: "+ api_key)
|
|
|
+
|
|
|
+ payload = {
|
|
|
+ "sender":
|
|
|
+ {
|
|
|
+ "email":from_address,
|
|
|
+ "name":"BOT DESCARGA DF"
|
|
|
+ },
|
|
|
+ "to":[{"email":to_address}],
|
|
|
+ "htmlContent":message,
|
|
|
+ "subject":subject
|
|
|
+ }
|
|
|
+ headers = {
|
|
|
+ 'accept': "application/json",
|
|
|
+ 'content-type': "application/json",
|
|
|
+ 'api-key': api_key
|
|
|
+ }
|
|
|
+
|
|
|
+ self.logger.debug("Enviando correo electrónico")
|
|
|
+
|
|
|
+ response = requests.request("POST", url, json=payload, headers=headers, verify=False)
|
|
|
+
|
|
|
+ self.logger.debug("Correo Electrónico enviado")
|
|
|
+ self.logger.info("Correo electrónico enviado con éxito a la dirección {0}".format(to_address))
|
|
|
|
|
|
|
|
|
|