Last active
August 24, 2023 01:58
-
-
Save p53ud0k0d3/8b8e973b00eecdeefd4f to your computer and use it in GitHub Desktop.
Simple python program for sending emails from Gmail and Hotmail.
This file contains hidden or 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
"""python-mailer.py | |
Author : Vishnu Ashok | |
Contact : [email protected] | |
[email protected] | |
GitHub : http://github.com/p53ud0k0d3 | |
This is a simple email client program, which can be used to send emails from Gmail and Hotmail. | |
You must enable "Allow less secure apps" in Gmail settings. | |
""" | |
import smtplib | |
import string | |
def main(): | |
print "======" | |
print "MAILER" | |
print "======\n\n" | |
print "1. Gmail\n2. Hotmail\n3. Exit" | |
ch = int(raw_input("Select an option : ")) | |
if ch == 1: | |
gmail() | |
elif ch == 2: | |
hotmail() | |
elif ch == 3: | |
exit() | |
else: | |
print "Invalid option" | |
def gmail(): | |
print "\n" | |
uid = raw_input("Gmail_id : ") | |
pwd = raw_input("Password : ") | |
to = raw_input("\nTo : ") | |
subject = raw_input("Subject : ") | |
content = raw_input("Message : ") | |
mail_server = 'smtp.gmail.com' | |
message = string.join(( | |
"From : %s" % uid, | |
"To : %s" % to, | |
"Subject : %s" % subject, | |
"", | |
content, | |
), "\r\n") | |
send_mail(uid, pwd, to, message, mail_server) | |
def hotmail(): | |
print "\n" | |
uid = raw_input("Hotmail_id : ") | |
pwd = raw_input("Password : ") | |
to = raw_input("\nTo : ") | |
subject = raw_input("Subject : ") | |
content = raw_input("Message : ") | |
mail_server = 'smptp.live.com' | |
message = string.join(( | |
"From : %s" % uid, | |
"To : %s" % to, | |
"Subject : %s" % subject, | |
"", | |
content, | |
), "\r\n") | |
send_mail(uid, pwd, to, message, mail_server) | |
def send_mail(uid, pwd, to, message, mail_server): | |
server = smtplib.SMTP(mail_server, 587) | |
server.ehlo() | |
server.starttls() | |
server.ehlo() | |
server.login(uid, pwd) | |
server.sendmail(uid, to, message) | |
server.close() | |
if __name__ == "__main__": | |
main() |
I think you should create application passwords to avoid having to reduce the security of your account (available both on Hotmail and Gmail).
I can’t connect to the gmail server. What can I do to solve this?
I think there is an option to enable less secure applications on your google account.
https://support.google.com/accounts/answer/6010255?hl=en
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really useful. Just a quick note - I think using the getpass module instead of raw_input would be helpful for passwords.