So I have a simple (needing work still!) python/twisted mail server, that supports plain text / TLS mails. I've also just written a simple client program, using smtplib.
If I connect to my server using telnet, ESMTP is advertised, then after I issue my EHLO, STARTTLS is advertised, as follows:
# telnet localhost 5000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 localhost.localdomain NO UCE NO UBE NO RELAY PROBES ESMTP
ehlo me
250-localhost.localdomain Hello 127.0.0.1, nice to meet you
250 STARTTLS
All good so far. However, I've read online of a bug related to smtplib's smtp_ssl class (see: http://bugs.python.org/issue4066 and Failing to send email with the Python example), and so people are suggesting solutions such as I have now tried, as below:
server = smtplib.SMTP('localhost', 5000) # my server is running on port 5000. Don't ask ;)
server.ehlo()
server.starttls('/opt/tesa/etc/certs/client/client.key', '/opt/tesa/etc/certs/client/client.crt')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
This successfully sends my message - but by the looks of it, over plain text. Output from the client looks like it is only seeing the first line of the server's EHLO 250 response (the "nice to meet you") - and NOT seeing the STARTTLS. I assume therefore, that it is not issuing it's own STARTTLS (since it would only do this if the server advertised it?) - and therefore stays as a plain text mail?
# python smtplib_client.py
From: me@home.com
To: you@work.com
Enter message, end with ^D (Unix) or ^Z (Windows):
fsdfds
Message length is 45
**send: 'ehlo localhost.localdomain\r\n'
reply: '250 localhost.localdomain Hello 127.0.0.1, nice to meet you\r\n'
reply: retcode (250); Msg: localhost.localdomain Hello 127.0.0.1, nice to meet you
send: 'mail FROM:<me@home.com>\r\n'**
reply: '250 Sender address accepted\r\n'
reply: retcode (250); Msg: Sender address accepted
send: 'rcpt TO:<you@work.com>\r\n'
reply: '250 Recipient address accepted\r\n'
reply: retcode (250); Msg: Recipient address accepted
send: 'data\r\n'
reply: '354 Continue\r\n'
reply: retcode (354); Msg: Continue
data: (354, 'Continue')
send: 'From: me@home.com\r\nTo: you@work.com\r\n\r\nfsdfds\r\n.\r\n'
reply: '250 Delivery in progress\r\n'
reply: retcode (250); Msg: Delivery in progress
data: (250, 'Delivery in progress')
send: 'quit\r\n'
reply: '221 See you later\r\n'
reply: retcode (221); Msg: See you later
Can anyone switch the lights on for me? I seem to be in the dark here!
(Using Python 2.6.6)
Thanks as ever...