diff --git a/CTFd/config.ini b/CTFd/config.ini index d15bf419..bc4aedc5 100644 --- a/CTFd/config.ini +++ b/CTFd/config.ini @@ -84,6 +84,14 @@ MAIL_TLS = # Whether to connect to the SMTP server over SSL MAIL_SSL = +# MAILSENDER_ADDR +# The email address that is responsible for the transmission of emails. +# This is very often the MAILFROM_ADDR value but can be specified if your email +# is delivered by a different domain than what's specified in your MAILFROM_ADDR. +# If this isn't specified, the MAILFROM_ADDR value is used. +# It is fairly rare to need to set this value. +MAILSENDER_ADDR = + # MAILGUN_API_KEY # Mailgun API key to send email over Mailgun. As of CTFd v3, Mailgun integration is deprecated. # Installations using the Mailgun API should migrate over to SMTP settings. diff --git a/CTFd/config.py b/CTFd/config.py index 7daf6374..b4d7da8d 100644 --- a/CTFd/config.py +++ b/CTFd/config.py @@ -147,6 +147,8 @@ class ServerConfig(object): MAIL_SSL: bool = process_boolean_str(config_ini["email"]["MAIL_SSL"]) + MAILSENDER_ADDR: str = empty_str_cast(config_ini["email"]["MAILSENDER_ADDR"]) + MAILGUN_API_KEY: str = empty_str_cast(config_ini["email"]["MAILGUN_API_KEY"]) MAILGUN_BASE_URL: str = empty_str_cast(config_ini["email"]["MAILGUN_API_KEY"]) diff --git a/CTFd/utils/email/smtp.py b/CTFd/utils/email/smtp.py index 6ef07460..66fadaa8 100644 --- a/CTFd/utils/email/smtp.py +++ b/CTFd/utils/email/smtp.py @@ -56,7 +56,15 @@ def sendmail(addr, text, subject): msg["From"] = mailfrom_addr msg["To"] = addr - smtp.send_message(msg) + # Check whether we are using an admin-defined SMTP server + custom_smtp = bool(get_config("mail_server")) + + # We should only consider the MAILSENDER_ADDR value on servers defined in config + if custom_smtp: + smtp.send_message(msg) + else: + mailsender_addr = get_app_config("MAILSENDER_ADDR") + smtp.send_message(msg, from_addr=mailsender_addr) smtp.quit() return True, "Email sent"