[shazni@shazniInWSO2 bin]$ python
Python 2.7.5 (default, Jun 25 2014, 10:19:55)
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> fromAddress="aaaaaaaaaaaa@gmail.com"
>>> toAddress="bbbbbbbbbbbb@yahoo.com"
>>> msg="Subject: Hello\n\nHi!! How are you"
>>> import smtplib
>>> server=smtplib.SMTP("smtp.gmail.com", 587)
>>> server.starttls()
(220, '2.0.0 Ready to start TLS')
>>> password="xxxxxxxxxxxxxx"
>>> server.login(fromAddress, password)
(235, '2.7.0 Accepted')
>>> server.sendmail(fromAddress, toAddress, msg)
{}
Replace 'aaaaaaaaaaaa', 'bbbbbbbbbbbb' and 'xxxxxxxxxxxxxx' accordingly.You can easily put this into a python script and invoke it and send a quick email to someone from the command line without ever opening your email account in a browser. Following is a sample script which does the same as above.
#!/usr/bin/python
import smtplib
import getpass
fromAddress = raw_input("Enter your gmail address: ")
toAddress = raw_input("Enter the recipients email address: ")
subject = raw_input('Enter the subject of email: ')
bodyText = raw_input('Enter the body text: ')
msg = "Subject: " + subject + "\n\n" + bodyText
#msg="Subject: Hello\n\nHi!! How are you"
server=smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
password = getpass.getpass('Gmail Password: ')
server.login(fromAddress, password)
server.sendmail(fromAddress, toAddress, msg)
A sample run of the script is shown below.[shazni@shazniInWSO2 Python]$ python sendEmail.py Enter your gmail address: mshazninazeer@gmail.com Enter the recipients email address: mshazninazeer@yahoo.com Enter the subject of email: Hello Enter the body text: This is a sample text sent to you by python!!! Gmail Password: [shazni@shazniInWSO2 Python]$Enjoy using python script to send emails