[Tutor] smtplib mail header problem

Liam Clarke-Hutchinson Liam.Clarke-Hutchinson at business.govt.nz
Tue Dec 6 22:13:40 CET 2005


Hi Dave, 

IIRC The first argument to sendmail() is the name of the account that's
sending... So when you include your subject there, it seems your ISP is
somewhat forgiving.

Liam Clarke-Hutchinson| Contact Centre Advisor| Ministry of Economic
Development 
DDI +64 3 962 2639 | Fax +64 3 962 6220
www.med.govt.nz 



-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On Behalf
Of dave s
Sent: Wednesday, 7 December 2005 9:41 a.m.
To: Python Tutor
Subject: [Tutor] smtplib mail header problem


Hi all,

I have a python script that works out & emails my employer with parts that I

have used. It has been great for 11ish months, now all my mail is classed as

spam & junked :(

Apparently the reason for it being junked is ...

'No subject' and 'No Sender'

I set up a small test script to isolate the problem using the core of the 
email code ...


#!/usr/bin/env python
# -*- coding: iso8859_1 -*- 


from smtplib import SMTP
from time import sleep, strftime
from datetime import datetime
import sys


email_SMTP = 'mail.pusspaws.net'
email_addr = 'jk at pusspaws.net'


def email_test():
  

    for trys in xrange(10):
        try:
                    
            mail_server = SMTP(email_SMTP)
            mail_server.login('XXXX', 'XXXX')
            
            
            subject = 'Test Email'
            from_ = 'Dave Selby<chubb at pusspaws.net>'
            to = email_addr
            return_path = email_addr
            
            blog="""Hi,\n\nThis is just a test"""
            
            msg = mail_headers(subject, from_, to, return_path) 
+'\r\n\r\n'+blog
            
            mail_server.sendmail(subject , email_addr, msg)
            
            mail_server.quit()
            
            # If we get to here, all is well, drop out of the loop
            break
            
        except:
            print 'Mailing error ... Re-trying ... '+str(trys+1)+' of 10\n'
            sleep(300)
            
    if trys==9:
        raise 'Mail Failure\n'+str(sys.exc_type)+'\n'+str(sys.exc_value)
    
    
    
    

def mail_headers(subject, from_, to, return_path):
    """
    Generate a formatted mail header string
    """
    
    header = 'Return-Path: ' + return_path 
    header = header + '\r\nFrom: ' + from_
    header = header + '\r\nReply-To: ' + return_path
    header = header + '\r\nTo: ' + to
    header = header + '\r\nSubject: '+subject

    now=datetime.now()

    day = now.strftime('%a')
    date = now.strftime('%d %b %Y %X')
    
    header = header + '\r\nDate : ' + day + ', ' + date + ' -0000\r\n'
    
    return (header)

    
email_test()



>From this I receive the following ....


Return-Path: <Test>
 Delivered-To: jk at pusspaws.user
 Received: (qmail 21696 invoked by uid 503); 6 Dec 2005 20:35:48 -0000
 Received: from unknown (HELO localhost.localdomain) (chubb at 86.130.36.111)
  by host201.com with SMTP; 6 Dec 2005 20:35:48 -0000
 Return-Path: jk at pusspaws.net
 From: Dave Selby<chubb at pusspaws.net>
 Reply-To: jk at pusspaws.net
 To: jk at pusspaws.net
 Subject: Test Email
 Date: Tue, 06 Dec 2005 20:35:47 -0000
 X-Bogosity: Ham, tests=bogofilter, spamicity=0.288675, version=0.95.2
 X-UID: 
 Status: R
 X-Status: NGC
 X-KMail-EncryptionState: 
 X-KMail-SignatureState: 
 X-KMail-MDN-Sent: 
 
Hi,

This is just a test


I cannot seem to set the top 'Return-path' correctly, any ideas how I do 
this ? also I have a sender so I am unsure why the spam filter picked this 
out.

Any suggestions

Cheers

dave
_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor

A new monthly electronic newsletter covering all aspects of MED's work is now available.  Subscribers can choose to receive news from any or all of seven categories, free of charge: Growth and Innovation, Strategic Directions, Energy and Resources, Business News, ICT, Consumer Issues and Tourism.  See http://news.business.govt.nz for more details.




http://www.govt.nz - connecting you to New Zealand central & local government services

Any opinions expressed in this message are not necessarily those of the Ministry of Economic Development. This message and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivery to the intended recipient, be advised that you have received this message in error and that any use is strictly prohibited. Please contact the sender and delete the message and any attachment from your computer.


More information about the Tutor mailing list