Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
protokollsystem
proto3
Commits
2147e03a
Commit
2147e03a
authored
Mar 01, 2017
by
Robin Sonnabend
Browse files
Enable unauthenticated mail sending
parent
de4fe2d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
config.py.example
View file @
2147e03a
...
...
@@ -10,8 +10,9 @@ DEBUG = False
MAIL_ACTIVE = True
MAIL_FROM = "protokolle@example.com"
MAIL_HOST = "mail.example.com:465"
MAIL_USER = "user"
MAIL_PASSWORD = "password"
MAIL_USER = "user" # set to "" for unauthenticated sending
MAIL_PASSWORD = "password" # set to "" for unauthenticated sending
MAIL_USE_TLS = True # should match the port in MAIL_HOST (if present there)
# (local) message queue (necessary)
CELERY_BROKER_URL = "redis://localhost:6379/0"
...
...
utils.py
View file @
2147e03a
...
...
@@ -69,14 +69,12 @@ class MailManager:
self
.
hostname
=
getattr
(
config
,
"MAIL_HOST"
,
""
)
self
.
username
=
getattr
(
config
,
"MAIL_USER"
,
""
)
self
.
password
=
getattr
(
config
,
"MAIL_PASSWORD"
,
""
)
self
.
use_tls
=
getattr
(
config
,
"MAIL_USE_TLS"
,
True
)
def
send
(
self
,
to_addr
,
subject
,
content
,
appendix
=
None
):
if
(
not
self
.
active
or
not
self
.
hostname
or
not
self
.
username
or
not
self
.
password
or
not
self
.
from_addr
):
print
(
"Not sending mail {} to {}"
.
format
(
subject
,
to_addr
))
return
msg
=
MIMEMultipart
(
"mixed"
)
# todo: test if clients accept attachment-free mails set to multipart/mixed
msg
[
"From"
]
=
self
.
from_addr
...
...
@@ -88,8 +86,9 @@ class MailManager:
part
=
MIMEApplication
(
file_like
.
read
(),
"octet-stream"
)
part
[
"Content-Disposition"
]
=
'attachment; filename="{}"'
.
format
(
name
)
msg
.
attach
(
part
)
server
=
smtplib
.
SMTP_SSL
(
self
.
hostname
)
server
.
login
(
self
.
username
,
self
.
password
)
server
=
(
smtplib
.
SMTP_SSL
if
self
.
use_tls
else
smtplib
.
SMTP
)(
self
.
hostname
)
if
self
.
username
not
in
[
None
,
""
]
and
self
.
password
not
in
[
None
,
""
]:
server
.
login
(
self
.
username
,
self
.
password
)
server
.
sendmail
(
self
.
from_addr
,
to_addr
,
msg
.
as_string
())
server
.
quit
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment