Ever wondered how you could send an e-mail to someone without actually opening the mailbox in your browser, or opening its desktop client? Don't want to go through the tedious process of entering the username and then password? Well, here's a tiny bit of Python code which you can use to send an email to someone. All you need to do is run the program, and that's it!
Now, the code for the e-mail client goes as follows ...
import smtplib
sender = 'YOUR EMAIL HERE'
receivers = ['RECEIVERS EMAIL HERE']
message = """From: From Person
To: To Person
Subject: Something ...
Huraah! It work's!
"""
try:
smtpObj = smtplib.SMTP('HOST'S SMTP SERVER ADDRESS HERE')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"
Now, SMTP is basically a module in Python, which consists of lots of networking-related functions, and hence we import that in our program. When we are creating smtpObj object, we have to provide the SMTP server address of the host, be it Gmail or Outlook. Here, if you are sending the mail from your gmail account, you need to write 'smtp.gmail.com' in HOST's SERVER ADDRESS, and 'smtp-mail.outlook.com', when sending through your Outlook ID. As simple as that!
NOTE: Information cited from www.tutorialspoint.com.
For further explanation on this topic, please refer this.

waoo well written post about "How to send e-mail with a simple Python program?"
ReplyDeleteThanks,
Gold Updates