first commit
This commit is contained in:
7
base-config.yaml
Normal file
7
base-config.yaml
Normal file
@@ -0,0 +1,7 @@
|
||||
sender_addr: "mail@tld.com"
|
||||
sender_passwd: "super_password123"
|
||||
smtp_server: "mail.stmp.com"
|
||||
smtp_port: 587
|
||||
|
||||
send_to: "mail.tld.com"
|
||||
|
||||
61
botMail.py
Normal file
61
botMail.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from typing import Type
|
||||
from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
|
||||
from maubot import Plugin, MessageEvent
|
||||
from maubot.handlers import command
|
||||
|
||||
import smtplib
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
import email
|
||||
import email.encoders
|
||||
|
||||
import re
|
||||
|
||||
class Config(BaseProxyConfig):
|
||||
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
||||
helper.copy("sender_addr")
|
||||
helper.copy("sender_passwd")
|
||||
helper.copy("stmp_server")
|
||||
helper.copy("smtp_port")
|
||||
helper.copy("send_to")
|
||||
|
||||
class MailBot(Plugin):
|
||||
async def start(self) -> None:
|
||||
#self.on_external_config_update()
|
||||
self.config.load_and_update()
|
||||
|
||||
@command.new(name="mail")
|
||||
@command.argument("pattern", pass_raw=True, required=True)
|
||||
async def command(self, evt: MessageEvent, pattern: str) -> None:
|
||||
await evt.mark_read()
|
||||
try:
|
||||
txtemail = re.search('<(.*)>', pattern)
|
||||
subject = txtemail.group(1)
|
||||
txtemail = re.sub('<(.*)>',"", pattern)
|
||||
|
||||
smtp_server=smtplib.SMTP(self.config["smtp_server"],self.config["smtp_port"])
|
||||
smtp_server.ehlo()
|
||||
smtp_server.starttls()
|
||||
smtp_server.ehlo()
|
||||
smtp_server.login(self.config["sender_addr"], self.config["sender_passwd"])
|
||||
|
||||
msg = MIMEMultipart()
|
||||
user = re.search('@(.*):', evt.sender)
|
||||
msg['From'] = user.group(1) + '<' + self.config["sender_addr"] + '>'
|
||||
self.log.info(msg['From'])
|
||||
msg['To'] = self.config["send_to"]
|
||||
msg['Subject'] = subject
|
||||
msg['Date'] = email.utils.formatdate(localtime=True)
|
||||
body = txtemail
|
||||
msg.attach(MIMEText(body))
|
||||
smtp_server.sendmail(msg['From'],msg['To'],msg.as_string())
|
||||
self.log.info(msg.as_string())
|
||||
await evt.respond('Mail envoyé')
|
||||
except:
|
||||
await evt.respond('Erreur envoi mail')
|
||||
await evt.respond("""!mail <Object>Corps du message""")
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_config_class(cls) -> Type[BaseProxyConfig]:
|
||||
return Config
|
||||
9
maubot.yaml
Normal file
9
maubot.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
maubot: 0.1.0
|
||||
id: tfa.mailBot
|
||||
version: 0.0.1
|
||||
license: AGPL-3.0-or-later
|
||||
modules:
|
||||
- botMail
|
||||
main_class: MailBot
|
||||
extra_files:
|
||||
- base-config.yaml
|
||||
Reference in New Issue
Block a user