Ok, what about sending email? What sounds like a big, scary subject is actually pretty simple once you get down to it. And because of Python's amazingly clear syntax it's very clean, not to mention compact.
Admit it, how much smaller is that than you expected! Before we delve deeper into this function, you need to understand a little about how it's being called or chances are you'll end up with errors!
The first argument here is a sequence of two or more addresses, the first being the 'From' address and the rest 'To' addresses. Followed by the 'Subject' and 'Message'. You may also need to tell this function what host you want to use if one isn't available locally. For this example we started by importing the 'smtplib' module, which provides functions/classes for sending emails from Python... so mail() is really just a wrapper over what you would normally do to send email, but it does make things easier! That is to say, inside mail() we do two main things...
If you plan on playing with 'smptlib' or similar modules, then you'll probably end up thanking the programmer who wrote it, for the set_debuglevel() method! As is my experience, anything that could go wrong will go wrong the first few times i.e.:
blog comments powered by Disqus |