mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 11:32:38 +02:00
email.py: added message id and local_hostname to get better formed messages, far from spams (#172)
Co-authored-by: Emmanuel Courcelle & Projet Internet et Citoyenneté <picadmin@le-pic.org>
This commit is contained in:
parent
0485ff4305
commit
3df9dd6115
3 changed files with 15 additions and 1 deletions
|
@ -168,6 +168,7 @@ export COPANIER_SMTP_HOST="mail.gandi.net"
|
||||||
export COPANIER_SMTP_PASSWORD="something"
|
export COPANIER_SMTP_PASSWORD="something"
|
||||||
export COPANIER_SMTP_LOGIN="yourlogin"
|
export COPANIER_SMTP_LOGIN="yourlogin"
|
||||||
export COPANIER_FROM_EMAIL="youremail@tld.com"
|
export COPANIER_FROM_EMAIL="youremail@tld.com"
|
||||||
|
export COPANIER_DOMAIN="tld.com"
|
||||||
export COPANIER_EMAIL_SIGNATURE="The team"
|
export COPANIER_EMAIL_SIGNATURE="The team"
|
||||||
export COPANIER_STAFF="staff@email.com another@staff.com"
|
export COPANIER_STAFF="staff@email.com another@staff.com"
|
||||||
```
|
```
|
||||||
|
|
|
@ -11,6 +11,7 @@ SMTP_HOST = ""
|
||||||
SMTP_PASSWORD = ""
|
SMTP_PASSWORD = ""
|
||||||
SMTP_LOGIN = ""
|
SMTP_LOGIN = ""
|
||||||
FROM_EMAIL = ""
|
FROM_EMAIL = ""
|
||||||
|
DOMAIN = ""
|
||||||
STAFF = []
|
STAFF = []
|
||||||
HIDE_GROUPS_LINK = False
|
HIDE_GROUPS_LINK = False
|
||||||
LOCALE = "fr_FR.UTF-8"
|
LOCALE = "fr_FR.UTF-8"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from emails import Message
|
from emails import Message
|
||||||
|
import email.utils as utils
|
||||||
|
|
||||||
from . import config
|
from . import config
|
||||||
|
|
||||||
|
@ -7,8 +8,10 @@ def send(to, subject, body, html=None, copy=None, attachments=None, mail_from=No
|
||||||
if not attachments:
|
if not attachments:
|
||||||
attachments = []
|
attachments = []
|
||||||
|
|
||||||
|
# compute a message id, this is good for spam score
|
||||||
|
mid = utils.make_msgid(domain=config.FROM_EMAIL.partition('@')[2])
|
||||||
message = Message(
|
message = Message(
|
||||||
text=body, html=html, subject=subject, mail_from=config.FROM_EMAIL
|
text=body, html=html, subject=subject, mail_from=config.FROM_EMAIL, message_id=mid
|
||||||
)
|
)
|
||||||
|
|
||||||
for filename, attachment, mime in attachments:
|
for filename, attachment, mime in attachments:
|
||||||
|
@ -18,12 +21,20 @@ def send(to, subject, body, html=None, copy=None, attachments=None, mail_from=No
|
||||||
body = body.replace("https", "http")
|
body = body.replace("https", "http")
|
||||||
return print("Sending email", str(body.encode('utf-8')), flush=True)
|
return print("Sending email", str(body.encode('utf-8')), flush=True)
|
||||||
|
|
||||||
|
# If the DOMAIN configuration parameter is configured, take it as HELO parameter
|
||||||
|
# Else, take None, the sender's fqdn will be computed by the library
|
||||||
|
# cf. https://docs.python.org/3/library/smtplib.html
|
||||||
|
domain = config.DOMAIN
|
||||||
|
if domain == "":
|
||||||
|
domain = None
|
||||||
|
|
||||||
# if no SMTP_LOGIN specified, don't create user and password fields, as the smtp server don't want them !
|
# if no SMTP_LOGIN specified, don't create user and password fields, as the smtp server don't want them !
|
||||||
if config.SMTP_LOGIN=="":
|
if config.SMTP_LOGIN=="":
|
||||||
smtp={
|
smtp={
|
||||||
"host": config.SMTP_HOST,
|
"host": config.SMTP_HOST,
|
||||||
"port": "25",
|
"port": "25",
|
||||||
"ssl": False,
|
"ssl": False,
|
||||||
|
"local_hostname": domain
|
||||||
}
|
}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -33,6 +44,7 @@ def send(to, subject, body, html=None, copy=None, attachments=None, mail_from=No
|
||||||
"password": config.SMTP_PASSWORD,
|
"password": config.SMTP_PASSWORD,
|
||||||
"port": "25",
|
"port": "25",
|
||||||
"ssl": False,
|
"ssl": False,
|
||||||
|
"local_hostname": domain
|
||||||
}
|
}
|
||||||
|
|
||||||
message.send(
|
message.send(
|
||||||
|
|
Loading…
Reference in a new issue