Created
October 21, 2021 04:38
-
-
Save lnksz/91be8f9872cc39f936c7ea2571313391 to your computer and use it in GitHub Desktop.
round-mail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
# -*- encoding: utf-8 -*- | |
# Send out "personalised" text mails to a list of people, | |
# without Cc hacks and without sharing the addresses. | |
# Uses a gmail account, with "less secure apps" enabled. | |
# Awaits own address in environment var "U" and password in environment var "P" | |
# $ [email protected] P=secret ./thisscript.py | |
# Note: leading space in the terminal should exlude the command from history | |
import smtplib, ssl | |
from email.message import EmailMessage | |
import os | |
mailtxt = \ | |
""" | |
Hi {}! | |
Lorem ipsum and some more text! | |
BR, | |
lnksz | |
""" | |
recipients = ( | |
{"name": u"Béla", "mail": "[email protected]"}, | |
{"name": u"Aladár", "mail": "[email protected]"}) | |
def main(): | |
u = os.environ.get('U') | |
p = os.environ.get('P') | |
ssl_context = ssl.create_default_context() | |
service = smtplib.SMTP_SSL('smtp.gmail.com', 465, context=ssl_context) | |
service.login(u, p) | |
print(f"Sending as {u}") | |
for r in recipients: | |
print(f"Mailing {r['name']}") | |
msg = EmailMessage() | |
msg['From'] = u | |
msg['Subject'] = 'roundmail' | |
msg['To'] = r['mail'] | |
msg.set_content(mailtxt.format(r['name'])) | |
service.send_message(msg) | |
service.quit() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
on my system
/bin/env python
is py3, you may need to addpython3
there on some older Debian/Ubuntu distros