Skip to content

Commit

Permalink
Add host and port variables to Email and Email_helper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
shincap8 committed Sep 6, 2024
1 parent 47985c4 commit d84f02e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions api/infrastructure/email/mail_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def __init__(self):

self.login = os.getenv("MAIL_LOGIN")
self.pwd = os.getenv("MAIL_PASSWORD")
self.host = os.getenv("SMTP_HOST")
self.port = os.getenv("SMTP_PORT")

self.local_dir = pathlib.Path(__file__).parent

Expand All @@ -35,7 +37,6 @@ def _read_template(self, filename):
return Template(template_file_content)

def send(self, contact, cc_contact=None, template_name="", msg_dict={}, subject=""):

try:
msg = MIMEMultipart()
message_template = self._read_template(template_name)
Expand All @@ -47,7 +48,7 @@ def send(self, contact, cc_contact=None, template_name="", msg_dict={}, subject=
msg.set_charset("utf-8")
msg["Subject"] = subject
msg.attach(MIMEText(message, "plain"))
server = smtplib.SMTP("smtp.gmail.com", 587)
server = smtplib.SMTP(self.host, self.port)
server.ehlo()
server.starttls()
server.login(self.login, self.pwd)
Expand Down
5 changes: 4 additions & 1 deletion backend/app/domain/helpers/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class EmailHelper:
def __init__(self):
self.login = os.getenv("MAIL_LOGIN")
self.pwd = os.getenv("MAIL_PASSWORD")
self.port = os.getenv("SMTP_PORT")
self.host = os.getenv("SMTP_HOST")

self.local_dir = pathlib.Path(__file__).parent

def _read_template(self, filename):
Expand Down Expand Up @@ -53,7 +56,7 @@ def send(
msg.set_charset("utf-8")
msg["Subject"] = subject
msg.attach(MIMEText(message, "plain"))
server = smtplib.SMTP("smtp.gmail.com", 587)
server = smtplib.SMTP(self.host, self.port)
server.ehlo()
server.starttls()
server.login(self.login, self.pwd)
Expand Down

0 comments on commit d84f02e

Please sign in to comment.