Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mftp/env.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
# EMAIL
## Senders' Credentials (via SMTP)
FROM_EMAIL = "[email protected]" # Notification Sender Email-id
FROM_EMAIL_PASS = "**********" # App password for the above email-id
# SMTP Credentials
SMTP_HOST = "smtp.gmail.com"
FROM_EMAIL_USER = "xxxxxxxxxxxxxxxxxxxx" # Same as FROM_EMAIL in case of Gmail SMTP
Comment on lines 49 to +52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep a single env instead of duplicated ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FROM_EMAIL_USER is same as FROM_EMAIL in case of Gmail SMTP only. For AWS SES, we have a different SMTP Username, which is why I've kept it different.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove one of them as it is redundant

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user provides the smtp host and for any host they will need to give username and password

FROM_EMAIL_PASS = "xxxxxxxxxxxxxxxxxxxx" # App password in case of Gmail SMTP
## EMAIL - Receiver's Address
BCC_EMAIL_S = ["[email protected]", "[email protected]"] # Multiple mails for bcc
# BCC_EMAIL_S = ["[email protected]"] # This is how you can set single mail in a list
Expand Down
20 changes: 10 additions & 10 deletions mftp/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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):
Expand Down Expand Up @@ -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(FROM_EMAIL_USER, FROM_EMAIL_PASS)
logging.info(" [Logged In!]")
except Exception as e:
logging.error(f" Failed to log in ~ {str(e)}")
Expand Down Expand Up @@ -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(FROM_EMAIL_USER, FROM_EMAIL_PASS)
logging.info(" [Logged In!]")
except Exception as e:
logging.error(f" Failed to log in ~ {str(e)}")
Expand Down Expand Up @@ -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(FROM_EMAIL_USER, FROM_EMAIL_PASS)
logging.info(" [Logged In!]")
except Exception as e:
logging.error(f" Failed to log in ~ {str(e)}")
Expand Down