Internet Client programming
All internet clients are built on top of TCP
We talked about four internet clients: ftp, nntp, pop3, smtp
After covering ftp and nntp, Wesley began with an overview of email, how electronic mail as a system is complex and to operate it requires lots of working pieces:
- Message Transport Agent
- responsible for moving email, routing, queueing, sending of email.
- sendmail, postfix, qmail, exim (unix)
- exchange (windows)
- Message Transport System
- protocol used by MTAs to transfer email host-to-host
- Simple Mail Transfer Protocol
- Message User Agent
- protocol used to get email from servers client-to-host
- post office protocols
- internet message access protocols
- connect
- login
- send email
- quit
As we go to press, the code below, tailored specifically to work with Google's SMTP server, was tested to work on Windows 2000 & Vista, and Debian Linux 5.0 (Lenny):
def use_gmail_smtp(te, tffn, ttfs, subject, msg_body):A primer for the acronyms in the use_gmail_smtp() argument list:
from smtplib import SMTP
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
SMTP_server = 'smtp.gmail.com'
username = 'your gmail handle'
passwd = 'your gmail password'
msg = MIMEMultipart()
msg['From'] = tffn
msg['To'] = ttfs
msg['Subject'] = subject
msg.attach(MIMEText(msg_body))
server = SMTP(SMTP_server, 587)
server.ehlo() # see note below for Python 2.5 and 2.6 users
ssl_connection_errors = server.starttls()
ehlo_connection_errors = server.ehlo()
server.login(username, passwd)
server.sendmail('tpc247', (te, ), msg.as_string())
server.close()
- te is the target_email, the email address where you want the message to arrive
- tffn is the_from_field_name, what you want the user to see in the From: field's name portion. To tffn, Gmail will append <your_gmail_handle@gmail.com>
- ttfs is the_to_field_string, what you want the user to see in the To: field, usually in the format:
"Your Name <yourname@company.com>"
...resulting in the error:
server.helo()
ssl_connection_errors = server.starttls()
...
Traceback (most recent call last):It's a mystery to me why this error is only on the aforementioned version of Python, but switching the call out was the answer.
...
File "", line 11, in use_gmail_smtp
ssl_connection_errors = send_server.starttls()
File "C:\Python26\lib\smtplib.py", line 611, in starttls
...
SMTPException: STARTTLS extension not supported by server.
I tested my script on 3 different operating systems, each running at least two different versions of Python:
- Windows
- 2000: Python 2.6.1, 2.6.2
- Vista: Python 2.5.4, 2.6.1, 2.6.2
- Debian Linux 5.0 Lenny: Python 2.5.2, 2.6.1, 2.6.2
Please wait while the installer finishesand then the installation would stall and never complete. The workaround is to open a command prompt, and type:
determining your disk space requirements
msiexec.exe -package <mypackage.msi> –qrReference: http://bloggingabout.net/blogs/jpsmit/archive/2009/08/28/please-wait-while-the-installer-finishes-determining-your-disk-space-requirements-message-drives-me-nuts.aspx
For you who would like to use gmail to send emails that look like they come from your workplace, you can now do so without the "on behalf of" that make you look less than authentic.
Reference: http://gadgetwise.blogs.nytimes.com/2009/07/31/gmail-drops-the-dreaded-on-behalf-of-lingo/