Email considered as spam, why? Wrong headers?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luke14free
    New Member
    • Apr 2007
    • 79

    Email considered as spam, why? Wrong headers?

    Hello,
    I'm writing a simple mass mail application, it interacts with hMailServer and works quite well.
    My biggest problem, since the application works is that all my messages are considered as spam by gmail and many other important provider and are not reiceved by yahoo.
    I googled to found out what was the problem and I come up just with a possible header problem.
    Since I couldn't figure how to solve this problem i used an example of aspn and added some lines of code. Here is the "problemati c" part:
    Code:
    out = cStringIO.StringIO() 
    htmlin = cStringIO.StringIO(html)
    txtin = cStringIO.StringIO(text)
    	
    writer = MimeWriter.MimeWriter(out)
    
    writer.addheader("Subject", subject)
    writer.addheader("MIME-Version", "1.0")
    writer.addheader("From", "<b12nd2@galactica.it>")
    writer.addheader("Reply-To", "<b12nd2@galactica.it>")
    writer.addheader("Message-ID", "<%s@galactica.it>" % id("something"))
    writer.addheader("Date",strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
    I'm on windows xp italian version and python 2.5 .
    Thanks for helping,
    Luke
  • luke14free
    New Member
    • Apr 2007
    • 79

    #2
    This is my complete function, I set up everything but email doesn't work...
    Code:
    def createhtmlmail (from, to, html, text, subject):
    	
    	out = cStringIO.StringIO() # output buffer for our message 
    	htmlin = cStringIO.StringIO(html)
     	txtin = cStringIO.StringIO(text)
    	
    	writer = MimeWriter.MimeWriter(out)
    	#
    	# set up some basic headers... we put subject here
    	# because smtplib.sendmail expects it to be in the
    	# message body
    	#
    	writer.addheader("To", to)
    	writer.addheader("From", from)
    	writer.addheader("Subject", subject)
    	writer.addheader("MIME-Version", "1.0")
    	writer.addheader("From", "<b12nd2@galactica.it>")
    	writer.addheader("Reply-To", "<b12nd2@galactica.it>")
    	writer.addheader("Message-ID", email.Utils.make_msgid())
    	writer.addheader("Date",email.Utils.formatdate(localtime=1))
    	writer.addheader("Content-type", "Multipart/mixed")
    	#
    	# start the multipart section of the message
    	# multipart/alternative seems to work better
    	# on some MUAs than multipart/mixed
    	#
    	writer.startmultipartbody("alternative")
    	writer.flushheaders()
    	#
    	# the plain text section
    	#
    	subpart = writer.nextpart()
    	subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
    	pout = subpart.startbody("text/plain", [("charset", 'us-ascii')])
    	mimetools.encode(txtin, pout, 'quoted-printable')
    	txtin.close()
    	#
    	# start the html subpart of the message
    	#
    	subpart = writer.nextpart()
    	subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
    	#
    	# returns us a file-ish object we can write to
    	#
    	pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
    	mimetools.encode(htmlin, pout, 'quoted-printable')
    	htmlin.close()
    	#
    	# Now that we're done, close our writer and
    	# return the message body
    	#
    	writer.lastpart()
    	msg = out.getvalue()
    	out.close()
    	open("somefile.eml","wb").write(msg)
    	return msg

    Comment

    Working...