Skip to content

Instantly share code, notes, and snippets.

@alexandru
Created February 20, 2020 15:50
Show Gist options
  • Save alexandru/3589fb0213a14c0ea04dec5817e9acb0 to your computer and use it in GitHub Desktop.
Save alexandru/3589fb0213a14c0ea04dec5817e9acb0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import smtplib
import argparse
from datetime import datetime, timedelta
from email.message import EmailMessage
parser = argparse.ArgumentParser(description='Send email')
parser.add_argument(
'--smtp-host', dest='smtp_host',
type=str, help="SMTP host and port", required=True)
parser.add_argument(
'--smtp-user', dest='smtp_user',
type=str, help="SMTP user for login", required=True)
parser.add_argument(
'--smtp-pass', dest='smtp_pass',
type=str, help="SMTP password for login", required=True)
parser.add_argument(
'--to', dest='to_address',
type=str, help="TO address", required=True)
parser.add_argument(
'--from', dest='from_address',
type=str, help="FROM address", required=True)
parser.add_argument(
'--title', dest='title',
type=str, help="Mail title", required=True)
parser.add_argument(
'--body', dest='body',
type=str, help="Mail body", required=True)
args = parser.parse_args()
msg = EmailMessage()
msg.set_content(args.body)
msg['Subject'] = args.title
msg['From'] = args.from_address
msg['To'] = args.to_address
service = smtplib.SMTP_SSL(args.smtp_host)
# service.starttls()
service.login(args.smtp_user, args.smtp_pass)
service.send_message(msg)
service.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment