Skip to content

Instantly share code, notes, and snippets.

@kagarlickij
Created April 18, 2020 15:20
Show Gist options
  • Save kagarlickij/d33ecb5fbf1b0e2b1578d4a673000dd2 to your computer and use it in GitHub Desktop.
Save kagarlickij/d33ecb5fbf1b0e2b1578d4a673000dd2 to your computer and use it in GitHub Desktop.
Python snippet to send email
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
import sys
import os
smtpLogin = sys.argv[1]
smtpPassword = sys.argv[2]
smtpServer = sys.argv[3]
smtpPort= sys.argv[4]
msg = MIMEMultipart()
msg['From'] = "[email protected]"
msg['To'] = "[email protected]"
msg['Subject'] = "security alert"
message = f"Security incident in check {os.environ['BUILD_BUILDNUMBER']}"
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP(f'{smtpServer}: {smtpPort}')
server.starttls()
server.login(smtpLogin, smtpPassword)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment