mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Support smtplib for sending emails
Support mail delivery without a local MTA. Instead, an SMTP server can now be configured using the smtp-server option in the [notifications] section. In order to use this option, the value of the sendmail option must be empty. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
3f2654e79e
commit
de549fb2d5
2 changed files with 20 additions and 5 deletions
|
@ -1,6 +1,8 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import email.mime.text
|
import email.mime.text
|
||||||
|
import email.utils
|
||||||
|
import smtplib
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
@ -63,7 +65,6 @@ class Notification:
|
||||||
return body.rstrip()
|
return body.rstrip()
|
||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
sendmail = aurweb.config.get('notifications', 'sendmail')
|
|
||||||
sender = aurweb.config.get('notifications', 'sender')
|
sender = aurweb.config.get('notifications', 'sender')
|
||||||
reply_to = aurweb.config.get('notifications', 'reply-to')
|
reply_to = aurweb.config.get('notifications', 'reply-to')
|
||||||
reason = self.__class__.__name__
|
reason = self.__class__.__name__
|
||||||
|
@ -79,13 +80,26 @@ class Notification:
|
||||||
msg['Reply-to'] = reply_to
|
msg['Reply-to'] = reply_to
|
||||||
msg['To'] = to
|
msg['To'] = to
|
||||||
msg['X-AUR-Reason'] = reason
|
msg['X-AUR-Reason'] = reason
|
||||||
|
msg['Date'] = email.utils.formatdate(localtime=True)
|
||||||
|
|
||||||
for key, value in self.get_headers().items():
|
for key, value in self.get_headers().items():
|
||||||
msg[key] = value
|
msg[key] = value
|
||||||
|
|
||||||
|
sendmail = aurweb.config.get('notifications', 'sendmail')
|
||||||
|
if sendmail:
|
||||||
|
# send email using the sendmail binary specified in the
|
||||||
|
# configuration file
|
||||||
p = subprocess.Popen([sendmail, '-t', '-oi'],
|
p = subprocess.Popen([sendmail, '-t', '-oi'],
|
||||||
stdin=subprocess.PIPE)
|
stdin=subprocess.PIPE)
|
||||||
p.communicate(msg.as_bytes())
|
p.communicate(msg.as_bytes())
|
||||||
|
else:
|
||||||
|
# send email using smtplib; no local MTA required
|
||||||
|
server_addr = aurweb.config.get('notifications', 'smtp-server')
|
||||||
|
|
||||||
|
server = smtplib.SMTP(server_addr)
|
||||||
|
server.set_debuglevel(0)
|
||||||
|
server.sendmail(sender, recipient, msg.as_bytes())
|
||||||
|
server.quit()
|
||||||
|
|
||||||
|
|
||||||
class ResetKeyNotification(Notification):
|
class ResetKeyNotification(Notification):
|
||||||
|
|
|
@ -47,7 +47,8 @@ window_length = 86400
|
||||||
|
|
||||||
[notifications]
|
[notifications]
|
||||||
notify-cmd = /usr/local/bin/aurweb-notify
|
notify-cmd = /usr/local/bin/aurweb-notify
|
||||||
sendmail = /usr/bin/sendmail
|
sendmail =
|
||||||
|
smtp-server = localhost
|
||||||
sender = notify@aur.archlinux.org
|
sender = notify@aur.archlinux.org
|
||||||
reply-to = noreply@aur.archlinux.org
|
reply-to = noreply@aur.archlinux.org
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue