aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilo Casagrande <milo.casagrande@linaro.org>2015-02-11 15:36:52 +0800
committerMilo Casagrande <milo.casagrande@linaro.org>2015-02-11 15:37:46 +0800
commit5e623d0d3b7d5dd60abeb989a124ec9d032aa6e8 (patch)
tree927e273fae43ed6c6955d511e6b563c09529f4c1
parent39efa5850408c7af05e770b550b8253a3e797cbf (diff)
downloadkernel-ci-backend-5e623d0d3b7d5dd60abeb989a124ec9d032aa6e8.tar.gz
Make the email sender description optional.
* Define a new config argument for the email sender description. Change-Id: Ia3b192ffd17e944b62db1499375709d2db96a10c
-rwxr-xr-xapp/server.py9
-rw-r--r--app/utils/emails.py8
2 files changed, 13 insertions, 4 deletions
diff --git a/app/server.py b/app/server.py
index 7e623fd..79e07b3 100755
--- a/app/server.py
+++ b/app/server.py
@@ -77,6 +77,10 @@ topt.define(
topt.define(
"smtp_sender", default="", type=str, help="The sender email address")
topt.define(
+ "smtp_sender_desc",
+ default="",
+ type=str, help="The name/description of the sender email address")
+topt.define(
"send_delay", default=60*60+5, type=int,
help="The delay in sending the report emails, "
"default to 1 hour and 5 seconds"
@@ -108,11 +112,12 @@ class KernelCiBackend(tornado.web.Application):
mail_options = {
"host": topt.options.smtp_host,
- "user": topt.options.smtp_user,
+ "info_email": topt.options.info_email,
"password": topt.options.smtp_password,
"port": topt.options.smtp_port,
"sender": topt.options.smtp_sender,
- "info_email": topt.options.info_email
+ "sender_desc": topt.options.smtp_sender_desc,
+ "user": topt.options.smtp_user
}
if self.mongodb_client is None:
diff --git a/app/utils/emails.py b/app/utils/emails.py
index 5be36c5..c55eb8f 100644
--- a/app/utils/emails.py
+++ b/app/utils/emails.py
@@ -38,7 +38,7 @@ def send_email(to_addrs, subject, body, mail_options):
status = models.ERROR_STATUS
msg = email.mime.text.MIMEText(body, _charset="utf_8")
- msg['Subject'] = subject
+ msg["Subject"] = subject
m_get = mail_options.get
port = m_get("port")
@@ -46,9 +46,13 @@ def send_email(to_addrs, subject, body, mail_options):
user = m_get("user")
password = m_get("password")
from_addr = m_get("sender")
+ sender_desc = m_get("sender_desc", None)
- msg["From"] = from_addr
msg["To"] = ", ".join(to_addrs)
+ if sender_desc:
+ msg["From"] = "%s <%s>" % (sender_desc, from_addr)
+ else:
+ msg["From"] = from_addr
if all([from_addr, host]):
server = None