From 7af76d0a11d850db0d849bd0bd8cd39420c393d7 Mon Sep 17 00:00:00 2001 From: Harshbansal8705 Date: Fri, 21 Nov 2025 19:03:20 +0530 Subject: [PATCH 1/2] feat: refactor email config to allow SMTP hosts other than Gmail --- mftp/README.md | 4 ++-- mftp/env.example.py | 4 +++- mftp/mail.py | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/mftp/README.md b/mftp/README.md index 297b015..35cd1bf 100644 --- a/mftp/README.md +++ b/mftp/README.md @@ -230,11 +230,11 @@ _Now that the environment has been set up and configured to properly compile and - ##### Using SMTP > `--smtp` - [Create an app password](https://support.google.com/accounts/answer/185833?hl=en) for the senders' email. - - After creating app password use it as your `FROM_EMAIL_PASS` value in next step. + - After creating app password use it as your `SMTP_PASS` value in next step. - ##### Using GMAIL API > `--gmail-api` - Follow this [quick start guide](https://developers.google.com/gmail/api/quickstart/python) to configure _gmail api_ on the senders' mail. - - After successfull configuration of gmail api, you can leave the value of `FROM_EMAIL_PASS` as it is in the next step. + - After successfull configuration of gmail api, you can leave the value of `SMTP_PASS` as it is in the next step. - Save the generated token as `mail_send_token.json` 4. #### Configuring environment variables diff --git a/mftp/env.example.py b/mftp/env.example.py index 75f92a3..99a666d 100644 --- a/mftp/env.example.py +++ b/mftp/env.example.py @@ -46,8 +46,10 @@ # EMAIL ## Senders' Credentials (via SMTP) +SMTP_HOST = "smtp.gmail.com" +SMTP_USER = "xxxxxxxxxxxxxxxxxxxx" # Same as FROM_EMAIL in case of Gmail SMTP +SMTP_PASS = "xxxxxxxxxxxxxxxxxxxx" # App password in case of Gmail SMTP FROM_EMAIL = "abc@gmail.com" # Notification Sender Email-id -FROM_EMAIL_PASS = "**********" # App password for the above email-id ## EMAIL - Receiver's Address BCC_EMAIL_S = ["xyz@googlegroups.com", "abc@googlegroups.com"] # Multiple mails for bcc # BCC_EMAIL_S = ["xyz@googlegroups.com"] # This is how you can set single mail in a list diff --git a/mftp/mail.py b/mftp/mail.py index f0ec41f..4f04800 100644 --- a/mftp/mail.py +++ b/mftp/mail.py @@ -5,7 +5,7 @@ from email.mime.text import MIMEText from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart -from env import FROM_EMAIL, FROM_EMAIL_PASS, BCC_EMAIL_S, HOSTER_EMAIL, HOSTER_INTERESTED_ROLLS, HOSTER_NAME, ROLL_MAIL, ROLL_NAME +from env import FROM_EMAIL, SMTP_HOST, SMTP_USER, SMTP_PASS, BCC_EMAIL_S, HOSTER_EMAIL, HOSTER_INTERESTED_ROLLS, HOSTER_NAME, ROLL_MAIL, ROLL_NAME def send_shortlists(mails, gmail_api, smtp): @@ -37,11 +37,11 @@ def send_shortlists(mails, gmail_api, smtp): import smtplib context = ssl.create_default_context() - logging.info(" [Connecting to smtp.google.com] ...") - with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server: + logging.info(f" [Connecting to {SMTP_HOST}] ...") + with smtplib.SMTP_SSL(SMTP_HOST, 465, context=context) as server: logging.info(" [Connected!]") try: - server.login(FROM_EMAIL, FROM_EMAIL_PASS) + server.login(SMTP_USER, SMTP_PASS) logging.info(" [Logged In!]") except Exception as e: logging.error(f" Failed to log in ~ {str(e)}") @@ -172,11 +172,11 @@ def send_companies(mail, gmail_api, smtp): import smtplib context = ssl.create_default_context() - logging.info(" [Connecting to smtp.google.com] ...") - with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server: + logging.info(f" [Connecting to {SMTP_HOST}] ...") + with smtplib.SMTP_SSL(SMTP_HOST, 465, context=context) as server: logging.info(" [Connected!]") try: - server.login(FROM_EMAIL, FROM_EMAIL_PASS) + server.login(SMTP_USER, SMTP_PASS) logging.info(" [Logged In!]") except Exception as e: logging.error(f" Failed to log in ~ {str(e)}") @@ -286,11 +286,11 @@ def send_notices(mails, smtp, gmail_api, notice_db): import smtplib context = ssl.create_default_context() - logging.info(" [Connecting to smtp.google.com] ...") - with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server: + logging.info(f" [Connecting to {SMTP_HOST}] ...") + with smtplib.SMTP_SSL(SMTP_HOST, 465, context=context) as server: logging.info(" [Connected!]") try: - server.login(FROM_EMAIL, FROM_EMAIL_PASS) + server.login(SMTP_USER, SMTP_PASS) logging.info(" [Logged In!]") except Exception as e: logging.error(f" Failed to log in ~ {str(e)}") From 19df0258b75ab09c9cbf10b052cdf5490561c63d Mon Sep 17 00:00:00 2001 From: Harshbansal8705 Date: Mon, 24 Nov 2025 13:30:51 +0530 Subject: [PATCH 2/2] chore: Refactor the config variables to keep it consistent with earlier versions --- mftp/README.md | 4 ++-- mftp/env.example.py | 7 ++++--- mftp/mail.py | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/mftp/README.md b/mftp/README.md index 35cd1bf..297b015 100644 --- a/mftp/README.md +++ b/mftp/README.md @@ -230,11 +230,11 @@ _Now that the environment has been set up and configured to properly compile and - ##### Using SMTP > `--smtp` - [Create an app password](https://support.google.com/accounts/answer/185833?hl=en) for the senders' email. - - After creating app password use it as your `SMTP_PASS` value in next step. + - After creating app password use it as your `FROM_EMAIL_PASS` value in next step. - ##### Using GMAIL API > `--gmail-api` - Follow this [quick start guide](https://developers.google.com/gmail/api/quickstart/python) to configure _gmail api_ on the senders' mail. - - After successfull configuration of gmail api, you can leave the value of `SMTP_PASS` as it is in the next step. + - After successfull configuration of gmail api, you can leave the value of `FROM_EMAIL_PASS` as it is in the next step. - Save the generated token as `mail_send_token.json` 4. #### Configuring environment variables diff --git a/mftp/env.example.py b/mftp/env.example.py index 99a666d..c7ccf2f 100644 --- a/mftp/env.example.py +++ b/mftp/env.example.py @@ -46,10 +46,11 @@ # EMAIL ## Senders' Credentials (via SMTP) -SMTP_HOST = "smtp.gmail.com" -SMTP_USER = "xxxxxxxxxxxxxxxxxxxx" # Same as FROM_EMAIL in case of Gmail SMTP -SMTP_PASS = "xxxxxxxxxxxxxxxxxxxx" # App password in case of Gmail SMTP FROM_EMAIL = "abc@gmail.com" # Notification Sender Email-id +# SMTP Credentials +SMTP_HOST = "smtp.gmail.com" +FROM_EMAIL_USER = "xxxxxxxxxxxxxxxxxxxx" # Same as FROM_EMAIL in case of Gmail SMTP +FROM_EMAIL_PASS = "xxxxxxxxxxxxxxxxxxxx" # App password in case of Gmail SMTP ## EMAIL - Receiver's Address BCC_EMAIL_S = ["xyz@googlegroups.com", "abc@googlegroups.com"] # Multiple mails for bcc # BCC_EMAIL_S = ["xyz@googlegroups.com"] # This is how you can set single mail in a list diff --git a/mftp/mail.py b/mftp/mail.py index 4f04800..8ba84c5 100644 --- a/mftp/mail.py +++ b/mftp/mail.py @@ -5,7 +5,7 @@ from email.mime.text import MIMEText from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart -from env import FROM_EMAIL, SMTP_HOST, SMTP_USER, SMTP_PASS, BCC_EMAIL_S, HOSTER_EMAIL, HOSTER_INTERESTED_ROLLS, HOSTER_NAME, ROLL_MAIL, ROLL_NAME +from env import FROM_EMAIL, SMTP_HOST, FROM_EMAIL_USER, FROM_EMAIL_PASS, BCC_EMAIL_S, HOSTER_EMAIL, HOSTER_INTERESTED_ROLLS, HOSTER_NAME, ROLL_MAIL, ROLL_NAME def send_shortlists(mails, gmail_api, smtp): @@ -41,7 +41,7 @@ def send_shortlists(mails, gmail_api, smtp): with smtplib.SMTP_SSL(SMTP_HOST, 465, context=context) as server: logging.info(" [Connected!]") try: - server.login(SMTP_USER, SMTP_PASS) + server.login(FROM_EMAIL_USER, FROM_EMAIL_PASS) logging.info(" [Logged In!]") except Exception as e: logging.error(f" Failed to log in ~ {str(e)}") @@ -176,7 +176,7 @@ def send_companies(mail, gmail_api, smtp): with smtplib.SMTP_SSL(SMTP_HOST, 465, context=context) as server: logging.info(" [Connected!]") try: - server.login(SMTP_USER, SMTP_PASS) + server.login(FROM_EMAIL_USER, FROM_EMAIL_PASS) logging.info(" [Logged In!]") except Exception as e: logging.error(f" Failed to log in ~ {str(e)}") @@ -290,7 +290,7 @@ def send_notices(mails, smtp, gmail_api, notice_db): with smtplib.SMTP_SSL(SMTP_HOST, 465, context=context) as server: logging.info(" [Connected!]") try: - server.login(SMTP_USER, SMTP_PASS) + server.login(FROM_EMAIL_USER, FROM_EMAIL_PASS) logging.info(" [Logged In!]") except Exception as e: logging.error(f" Failed to log in ~ {str(e)}")