Saturday, January 26, 2013

Sending email with gmail smtp in Python (it's simple and powerful)

Hi, I found two python code examples and I combine them and it works. Here is the sample code.

 This example send emails using gmail smtp service, so basically it is free and is possible even if you do not have an smtp server in the office :)

Enjoy! Python is powerful :)


Sample Code in Python 2.7:

import smtplib
from email.MIMEText import MIMEText

msg_text = 'my email content is here ... !!!'
msg = MIMEText(msg_text)
msg['Subject'] = 'Hello Subject'

server = smtplib.SMTP( "smtp.gmail.com", 587 )
server.starttls()
server.login('', '')
server.sendmail('', '', msg.as_string() )

print 'email sent successfully ... yahoo!!'


Save above code into a python code file, and then at Dos prompt, type Python example.py for example :)

Converting a Physical Linux to Virtual

Hmm ... I have done a lot of work on my Linux Lubuntu 15.10 with PHP and PostgreSQL and a few other things ... it is quite time-consuming to...