mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 14:04:20 +01:00
Add the ability to override the sender header of email via SMTP (#1657)
* Add the ability to override the sender header of email via SMTP with the `MAILSENDER_ADDR` config value * Closes #1644
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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"])
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user