For the code: "smtplib.SMTP('localhost')", you need 'localhost' to be a mail server that you have working.
Mine for example, was a free account I setup at
www.nerdshack.com, it worked very nicely. And I could recieve all the emails simply from Thunderbird/Outlook Explorer.
In that case, 'localhost' is replaced by: 'mail.nerdshack.com:2525'