Last active
April 26, 2024 22:15
-
-
Save IgnacioHeredia/5f8fd2fc7d56763e4060c7b8fc8e0212 to your computer and use it in GitHub Desktop.
Send emails with Hotmail
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
import argparse | |
import email | |
import smtplib | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--from_user', type=str) | |
parser.add_argument('--from_pwd', type=str) | |
parser.add_argument('--to_user', type=str) | |
parser.add_argument('--subject', type=str, default="") | |
parser.add_argument('--body', type=str, default="") | |
args = parser.parse_args() | |
msg = email.message_from_string(args.body) | |
msg['From'] = args.from_user | |
msg['To'] = args.to_user | |
msg['Subject'] = args.subject | |
msg['X-Priority'] = '1' # highest priority | |
s = smtplib.SMTP("smtp-mail.outlook.com", 587) | |
s.ehlo() # hostname to send for this command defaults to the fully qualified domain name of the local host. | |
s.starttls() # puts connection to SMTP server in TLS mode | |
s.ehlo() | |
s.login(args.from_user, args.from_pwd) | |
s.sendmail(args.from_user, args.to_user, msg.as_string()) | |
s.quit() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment