Created
April 18, 2020 15:20
-
-
Save kagarlickij/d33ecb5fbf1b0e2b1578d4a673000dd2 to your computer and use it in GitHub Desktop.
Python snippet to send email
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
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