Open darkcode357 opened 1 year ago
Hi @darkcode357,
This is an unofficial workaround.
I went through the same situation and to create a workaround I modified the file /ail-framework/bin/NotificationHelper.py adding the following pyhton library: SSL
import ssl
In the line which contains:
smtp_server = smtplib.SMTP(sender_host, sender_port)
I changed it to:
smtp_server = smtplib.SMTP_SSL(sender_host, sender_port,context=ssl_context)
Adding the following line after the imports:
ssl_context = ssl.creat_default_context()
And remove this line if you don't use TLS and config parser:
smtp_server.starttls()
sender = config_loader.get_config_str("Notifications", "sender")
sender_user = config_loader.get_config_str("Notifications", "sender_user")
sender_host = config_loader.get_config_str("Notifications", "sender_host")
sender_port = config_loader.get_config_int("Notifications", "sender_port")
sender_pw = config_loader.get_config_str("Notifications", "sender_pw")
That way you will see that my file is static and is not using the environment variable,
In this way it was possible to send the email with SSL support.
My file:
import os
import sys
import argparse
import traceback
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import ssl
ssl_context = ssl.create_default_context()
def sendEmailNotification(recipient, mail_subject, mail_body):
sender = 'EMAIL@test.com'
sender_user = 'EMAIL@test.com'
sender_host = 'smtp.gmail.com'
sender_port = 465
sender_pw = 'Password'
if sender_pw == 'None':
sender_pw = None
# raise an exception if any of these is None
if (sender is None or
sender_host is None or
sender_port is None
):
raise Exception('SMTP configuration (host, port, sender) is missing or incomplete!')
try:
if sender_pw is not None:
try:
##add ssl suporte
smtp_server = smtplib.SMTP_SSL(sender_host, sender_port,context=ssl_context)
except smtplib.SMTPNotSupportedError:
print("The server does not support the STARTTLS extension.")
smtp_server = smtplib.SMTP_SSL(sender_host, sender_port)
smtp_server.ehlo()
if sender_user is not None:
smtp_server.login(sender_user, sender_pw)
else:
smtp_server.login(sender, sender_pw)
else:
smtp_server = smtplib.SMTP(sender_host, sender_port)
mime_msg = MIMEMultipart()
mime_msg['From'] = sender
mime_msg['To'] = recipient
mime_msg['Subject'] = mail_subject
mime_msg.attach(MIMEText(mail_body, 'plain'))
smtp_server.sendmail(sender, recipient, mime_msg.as_string())
smtp_server.quit()
print('Send notification: ' + mail_subject + ' to '+recipient)
except Exception as err:
traceback.print_tb(err.__traceback__)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Test notification sender.')
parser.add_argument("addr", help="Test mail 'to' address")
args = parser.parse_args()
sendEmailNotification('EMAIL@email.com', '_mail test_', 'Success.')
If you need more help, let me know.
Name: Send Mail Addresses With SSL Certificate
Steps to reproduce
How'd you do it?
step 1 ->
Create a google accountstep 2 ->
Enable Two-step verificationstep 3 ->
Create a linux type app passwordstep 4 ->
Open the configuration file located inside ->./AIL-framework/configs/core.cfg
step 5 ->
I configured the lines below following the following model[Notifications] ail_domain =
'https://xpto:7000'
sender ='xpto@gmail.com'
sender_user ='xpto@gmail.com'
sender_host ='smtp.gmail.com'
sender_port ='465'
sender_pw ='masterpass'
Were you following a specific guide/tutorial or reading documentation?
I am not using any guide/tutorial or documentation
Expected behavior
What should happen?
Current behavior
What happens instead?
AIL version
Run the command to get my version
git log -1 --pretty=oneline
01f459109fa36473f66cc9c400c27a4cebf77858 (origin/master, origin/HEAD) chg: [feeder] rename bgp_monitor