mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 14:34:21 +01:00
Fix SMTP email From header and remove 'Admin' from the From header (#1229)
* Fix SMTP email From header and remove 'Admin' from the From header
This commit is contained in:
@@ -5,6 +5,8 @@ import requests
|
|||||||
def sendmail(addr, text, subject):
|
def sendmail(addr, text, subject):
|
||||||
ctf_name = get_config("ctf_name")
|
ctf_name = get_config("ctf_name")
|
||||||
mailfrom_addr = get_config("mailfrom_addr") or get_app_config("MAILFROM_ADDR")
|
mailfrom_addr = get_config("mailfrom_addr") or get_app_config("MAILFROM_ADDR")
|
||||||
|
mailfrom_addr = "{} <{}>".format(ctf_name, mailfrom_addr)
|
||||||
|
|
||||||
mailgun_base_url = get_config("mailgun_base_url") or get_app_config(
|
mailgun_base_url = get_config("mailgun_base_url") or get_app_config(
|
||||||
"MAILGUN_BASE_URL"
|
"MAILGUN_BASE_URL"
|
||||||
)
|
)
|
||||||
@@ -14,7 +16,7 @@ def sendmail(addr, text, subject):
|
|||||||
mailgun_base_url + "/messages",
|
mailgun_base_url + "/messages",
|
||||||
auth=("api", mailgun_api_key),
|
auth=("api", mailgun_api_key),
|
||||||
data={
|
data={
|
||||||
"from": "{} Admin <{}>".format(ctf_name, mailfrom_addr),
|
"from": mailfrom_addr,
|
||||||
"to": [addr],
|
"to": [addr],
|
||||||
"subject": subject,
|
"subject": subject,
|
||||||
"text": text,
|
"text": text,
|
||||||
|
|||||||
@@ -19,7 +19,10 @@ def get_smtp(host, port, username=None, password=None, TLS=None, SSL=None, auth=
|
|||||||
|
|
||||||
|
|
||||||
def sendmail(addr, text, subject):
|
def sendmail(addr, text, subject):
|
||||||
|
ctf_name = get_config("ctf_name")
|
||||||
mailfrom_addr = get_config("mailfrom_addr") or get_app_config("MAILFROM_ADDR")
|
mailfrom_addr = get_config("mailfrom_addr") or get_app_config("MAILFROM_ADDR")
|
||||||
|
mailfrom_addr = "{} <{}>".format(ctf_name, mailfrom_addr)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"host": get_config("mail_server") or get_app_config("MAIL_SERVER"),
|
"host": get_config("mail_server") or get_app_config("MAIL_SERVER"),
|
||||||
"port": int(get_config("mail_port") or get_app_config("MAIL_PORT")),
|
"port": int(get_config("mail_port") or get_app_config("MAIL_PORT")),
|
||||||
|
|||||||
@@ -355,7 +355,10 @@ def test_user_can_reset_password(mock_smtp):
|
|||||||
# Issue the password reset request
|
# Issue the password reset request
|
||||||
client.post("/reset_password", data=data)
|
client.post("/reset_password", data=data)
|
||||||
|
|
||||||
|
ctf_name = get_config("ctf_name")
|
||||||
from_addr = get_config("mailfrom_addr") or app.config.get("MAILFROM_ADDR")
|
from_addr = get_config("mailfrom_addr") or app.config.get("MAILFROM_ADDR")
|
||||||
|
from_addr = "{} <{}>".format(ctf_name, from_addr)
|
||||||
|
|
||||||
to_addr = "user@user.com"
|
to_addr = "user@user.com"
|
||||||
|
|
||||||
# Build the email
|
# Build the email
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ def test_sendmail_with_smtp_from_config_file(mock_smtp):
|
|||||||
app.config["MAIL_USERNAME"] = "username"
|
app.config["MAIL_USERNAME"] = "username"
|
||||||
app.config["MAIL_PASSWORD"] = "password"
|
app.config["MAIL_PASSWORD"] = "password"
|
||||||
|
|
||||||
|
ctf_name = get_config("ctf_name")
|
||||||
from_addr = get_config("mailfrom_addr") or app.config.get("MAILFROM_ADDR")
|
from_addr = get_config("mailfrom_addr") or app.config.get("MAILFROM_ADDR")
|
||||||
|
from_addr = "{} <{}>".format(ctf_name, from_addr)
|
||||||
|
|
||||||
to_addr = "user@user.com"
|
to_addr = "user@user.com"
|
||||||
msg = "this is a test"
|
msg = "this is a test"
|
||||||
|
|
||||||
@@ -47,7 +50,10 @@ def test_sendmail_with_smtp_from_db_config(mock_smtp):
|
|||||||
set_config("mail_username", "username")
|
set_config("mail_username", "username")
|
||||||
set_config("mail_password", "password")
|
set_config("mail_password", "password")
|
||||||
|
|
||||||
|
ctf_name = get_config("ctf_name")
|
||||||
from_addr = get_config("mailfrom_addr") or app.config.get("MAILFROM_ADDR")
|
from_addr = get_config("mailfrom_addr") or app.config.get("MAILFROM_ADDR")
|
||||||
|
from_addr = "{} <{}>".format(ctf_name, from_addr)
|
||||||
|
|
||||||
to_addr = "user@user.com"
|
to_addr = "user@user.com"
|
||||||
msg = "this is a test"
|
msg = "this is a test"
|
||||||
|
|
||||||
@@ -98,7 +104,7 @@ def test_sendmail_with_mailgun_from_config_file(fake_post_request):
|
|||||||
assert kwargs["data"] == {
|
assert kwargs["data"] == {
|
||||||
"to": ["user@user.com"],
|
"to": ["user@user.com"],
|
||||||
"text": "this is a test",
|
"text": "this is a test",
|
||||||
"from": "CTFd Admin <noreply@ctfd.io>",
|
"from": "CTFd <noreply@ctfd.io>",
|
||||||
"subject": "Message from CTFd",
|
"subject": "Message from CTFd",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +151,7 @@ def test_sendmail_with_mailgun_from_db_config(fake_post_request):
|
|||||||
assert kwargs["data"] == {
|
assert kwargs["data"] == {
|
||||||
"to": ["user@user.com"],
|
"to": ["user@user.com"],
|
||||||
"text": "this is a test",
|
"text": "this is a test",
|
||||||
"from": "CTFd Admin <noreply@ctfd.io>",
|
"from": "CTFd <noreply@ctfd.io>",
|
||||||
"subject": "Message from CTFd",
|
"subject": "Message from CTFd",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +173,10 @@ def test_verify_email(mock_smtp):
|
|||||||
set_config("mail_password", "password")
|
set_config("mail_password", "password")
|
||||||
set_config("verify_emails", True)
|
set_config("verify_emails", True)
|
||||||
|
|
||||||
|
ctf_name = get_config("ctf_name")
|
||||||
from_addr = get_config("mailfrom_addr") or app.config.get("MAILFROM_ADDR")
|
from_addr = get_config("mailfrom_addr") or app.config.get("MAILFROM_ADDR")
|
||||||
|
from_addr = "{} <{}>".format(ctf_name, from_addr)
|
||||||
|
|
||||||
to_addr = "user@user.com"
|
to_addr = "user@user.com"
|
||||||
|
|
||||||
with freeze_time("2012-01-14 03:21:34"):
|
with freeze_time("2012-01-14 03:21:34"):
|
||||||
|
|||||||
Reference in New Issue
Block a user