added class to write mails to users
This commit is contained in:
parent
d7dea7df00
commit
df32f3c614
|
@ -17,6 +17,14 @@ shutdown_contact_screen_name = 'links_tech'
|
|||
access_token_key = "876046057721008128-J35moxFXUvLb24MnaMVbVpqiEtxBlcc"
|
||||
access_token_secret = "I7PQZMHuJDS5WslgUhqEeZbEWGhwLhmOetvwFoTn8YDKW"
|
||||
|
||||
[mail]
|
||||
mailserver = "smtp.riseup.net"
|
||||
port = 587
|
||||
user = "ticketfrei"
|
||||
passphrase = "sup3rs3cur3"
|
||||
|
||||
|
||||
|
||||
# [trigger]
|
||||
# goodlists are one regex per line.
|
||||
# badlists are one badword per line.
|
||||
|
|
0
retootbot.py
Normal file → Executable file
0
retootbot.py
Normal file → Executable file
0
retweetbot.py
Normal file → Executable file
0
retweetbot.py
Normal file → Executable file
53
sendmail.py
Executable file
53
sendmail.py
Executable file
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import smtplib
|
||||
import pytoml as toml
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
|
||||
class Mailer(object):
|
||||
"""
|
||||
Maintains the connection to the mailserver and sends text to users.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
|
||||
:param config: The config file generated from config.toml
|
||||
"""
|
||||
# This generates the From address by stripping the part until the first
|
||||
# period from the mail server address and won't work always.
|
||||
self.fromaddr = config["mail"]["user"] + "@" + \
|
||||
config["mail"]["mailserver"].partition(".")[2]
|
||||
|
||||
# starts a client session with the SMTP server
|
||||
self.s = smtplib.SMTP(config["mail"]["mailserver"])
|
||||
self.s.starttls()
|
||||
self.s.login(config["mail"]["user"], config["mail"]["passphrase"])
|
||||
|
||||
def send(self, text, recipient, subject):
|
||||
"""
|
||||
|
||||
:param text: (string) the content of the mail
|
||||
:param recipient: (string) the recipient of the mail
|
||||
:param subject: (string) the subject of the mail
|
||||
:return: string for logging purposes, contains recipient & subject
|
||||
"""
|
||||
msg = MIMEText(text)
|
||||
|
||||
msg["From"] = self.fromaddr
|
||||
msg["To"] = recipient
|
||||
msg["Subject"] = subject
|
||||
|
||||
self.s.send_message(msg)
|
||||
|
||||
return "Sent mail to " + recipient + ": " + subject
|
||||
|
||||
# For testing:
|
||||
if __name__ == '__main__':
|
||||
# read config in TOML format (https://github.com/toml-lang/toml#toml)
|
||||
with open('config.toml') as configfile:
|
||||
config = toml.load(configfile)
|
||||
|
||||
m = Mailer(config)
|
||||
print(m.send("This is a test mail.", m.fromaddr, "Test"))
|
0
ticketfrei.py
Normal file → Executable file
0
ticketfrei.py
Normal file → Executable file
Loading…
Reference in a new issue