Skip to content
Snippets Groups Projects
Verified Commit 1e300b0f authored by Nico's avatar Nico
Browse files

add sendmail script

parent 5ab23da8
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python3
import smtplib
from email.message import EmailMessage
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("--recipients", type=argparse.FileType('r'), help="Recipients, one per line", required=True)
ap.add_argument("--message", type=argparse.FileType('r'), help="Message to send", required=True)
ap.add_argument("--subject", help="Message subject", required=True)
ap.add_argument("--sender", help="Mail from", required=True)
args = ap.parse_args()
message = args.message.read()
for line in args.recipients:
if line.startswith("#"):
continue
if not "@" in line:
print(f"Line does not seem to contain @-sign: {line}")
recipient = line.strip()
if len(line) < 1:
continue
print(f"Sending to {recipient}...")
msg = EmailMessage()
msg.set_content(message)
msg['Subject'] = args.subject
msg['From'] = args.sender
msg['To'] = recipient
# Send the message via our own SMTP server.
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment