diff --git a/config.template b/config.template index c2299b8..7049828 100644 --- a/config.template +++ b/config.template @@ -117,6 +117,7 @@ SMTP_SERVER = smtp.gmail.com SMTP_PORT = 587 # Sender email: be mindful of public access, don't use your personal email FROM_EMAIL = none@gmail.com +SMTP_AUTH = True SMTP_USERNAME = none@gmail.com SMTP_PASSWORD = none EMAIL_SUBJECT = Meshtastic✉️ diff --git a/modules/settings.py b/modules/settings.py index 3d8ed2b..75d1fde 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -180,6 +180,7 @@ try: SMTP_SERVER = config['smtp'].get('SMTP_SERVER', 'smtp.gmail.com') SMTP_PORT = config['smtp'].getint('SMTP_PORT', 587) FROM_EMAIL = config['smtp'].get('FROM_EMAIL', 'none@gmail.com') + SMTP_AUTH = config['smtp'].getboolean('SMTP_AUTH', True) SMTP_USERNAME = config['smtp'].get('SMTP_USERNAME', FROM_EMAIL) SMTP_PASSWORD = config['smtp'].get('SMTP_PASSWORD', 'password') EMAIL_SUBJECT = config['smtp'].get('EMAIL_SUBJECT', 'Meshtastic✉️') diff --git a/modules/smtp.py b/modules/smtp.py index bff0eed..55bfd0d 100644 --- a/modules/smtp.py +++ b/modules/smtp.py @@ -54,9 +54,15 @@ def send_email(to_email, message, nodeID=0): # Connect to SMTP server server = smtplib.SMTP(SMTP_SERVER, SMTP_PORT, timeout=SMTP_TIMEOUT) - if SMTP_PORT != 25: - server.starttls() - server.login(SMTP_USERNAME, SMTP_PASSWORD) + try: + # login /auth + if SMTP_PORT == 587: + server.starttls() + if SMTP_AUTH: + server.login(SMTP_USERNAME, SMTP_PASSWORD) + except Exception as e: + logger.warning(f"System: Failed to login to SMTP server: {str(e)}") + return # Send email; this command will hold the program until the email is sent server.send_message(msg)