Skip to content

Instantly share code, notes, and snippets.

@alexandru
Created March 18, 2020 08:53
Show Gist options
  • Save alexandru/f8c9c2f4fe194d80d80d2f9f7f4f98da to your computer and use it in GitHub Desktop.
Save alexandru/f8c9c2f4fe194d80d80d2f9f7f4f98da 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