From 92e7b98903752c1c62489627e32483bd620b4240 Mon Sep 17 00:00:00 2001 From: spongle Date: Sun, 18 Sep 2022 19:24:06 +0100 Subject: [PATCH] .. --- shared/attmail.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++ shared/sendkeys | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 shared/attmail.py diff --git a/shared/attmail.py b/shared/attmail.py new file mode 100755 index 0000000..22744c6 --- /dev/null +++ b/shared/attmail.py @@ -0,0 +1,57 @@ +import smtplib +# import the corresponding modules +from email import encoders +from email.mime.base import MIMEBase +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText + +async def main(): + with open('/zTools/zprivateConfig/secrets/config.toml') as f: + config = toml.load(f) + + port = config['attmail']['port'] + smtp_server = config['attmail']['smtp_server'] + login = config['attmail']['login'] # paste your login generated by Mailtrap + password = config['attmail']['password'] # paste your password generated by Mailtrap + + subject = "An example of boarding pass" + sender_email = config['attmail']['sender_email'] + receiver_email = config['attmail']['receiver_email'] + + msg = MIMEMultipart() + msg["From"] = sender_email + msg["To"] = receiver_email + msg["Subject"] = subject + + # Add body to email + body = "This is an example of how you can send a boarding pass in attachment with Python" + msg.attach(MIMEText(body, "plain")) + filename = "/var/tmp/keys.zip" + # Open PDF file in binary mode + # We assume that the file is in the directory where you run your Python script from + with open(filename, "rb") as attachment: + # The content type "application/octet-stream" means that a MIME attachment is a binary file + part = MIMEBase("application", "octet-stream") + part.set_payload(attachment.read()) + # Encode to base64 + encoders.encode_base64(part) + # Add header + part.add_header( + "Content-Disposition", + f"attachment; filename= {filename}", + ) + # Add attachment to your message and convert it to string + msg.attach(part) + text = msg.as_string() + # send your email + with smtplib.SMTP_SSL(smtp_server, port) as server: + server.login(login, password) + server.sendmail( + sender_email, receiver_email, text + ) + print('Sent') + + +if __name__ == '__main__': + main + diff --git a/shared/sendkeys b/shared/sendkeys index a1a73fa..182ed14 100755 --- a/shared/sendkeys +++ b/shared/sendkeys @@ -30,7 +30,7 @@ then echo "--------------------------------" cat ${KEYSTORE}/*.pub |sort | uniq zip /var/tmp/keys.zip ~/.mykeys/_*.pub - python3 /zTools/zPrivateConfig/bin/attmail.py + python3 ${BASE}/attmail.py rm -f /var/tmp/keys.zip else echo "ERROR: keystore not found"