Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41051

Re: This mail never gets delivered. Any ideas why?

From Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
Newsgroups comp.lang.python
Subject Re: This mail never gets delivered. Any ideas why?
Date 2013-03-11 06:25 +0100
Organization A newly installed InterNetNews server
Message-ID <khjpt4$r66$1@r03.glglgl.gl> (permalink)
References <fdc2a4d2-1967-4906-907e-3cf121694549@googlegroups.com>

Show all headers | View raw


Am 09.03.2013 22:20 schrieb Νίκος Γκρ33κ:
> 		SENDMAIL = '/usr/sbin/sendmail'
> 			
> 		FROM = mail
> 		TO = ['support@superhost.gr']
> 		SUBJECT = "Επικοινωνία πιθανού πελάτη!"
> 		TEXT = comment
>
> 		message = """\
> 				  From: %s
> 				  To: %s
> 				  Subject: %s
> 					
> 				  %s
> 				  """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
>
> 		p = os.popen("%s -t -i" % SENDMAIL, "w")
> 		p.write(message)
> 		status = p.close()
> 		if status != 256:
> 			print( "<h2><font color=lime>Ευχαριστώ πολύ για το ενδιαφέρον! Θα επικοινωνήσω μαζί σου άμεσα :-)</font></h2>" )
> 		else:
> 			print( "<h2><font color=red>Δυστυχώς δεν μπόρεσε να αποσταλεί το e-mail :-(" )
>
> ===============
>
> Do you see somehtign wrong in the above code?
>

I see some things here:

1. Your subject is not properly encoded.

All characters outside the ASCII area must be encoded in an appropriate 
way if you send an email. It MIGHT be the case that sendmail handles 
this for you, but probably not every version.

But that should not prevent sending the mail at all; probably some 
garbage would result.

2. You failed to tell us what "never gets delivered" means: do you get 
an error message?

3. You failed to give us a SSCCE <http://sscce.org/>: in order to test 
the code, I had to add several variable definitions and imports.

4., an I thik this is the point: you are indenting your message string.
If you put a print(message) somewhere into the code, you'll see that the 
email header lines don't start with the header names, but with spaces. 
That is something which sendmail cannot and won't handle. Likewise, the 
header-body-separator is probably broken as well.

Just write, even if your code is indented in some way:

  		message = """\
From: %s
To: %s
Subject: %s

%s""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

or maybe, just to be sure,

   		message = "From: %s\nTo: %s\nSubject: %s\n\n%s" % \
                     (FROM, ", ".join(TO), SUBJECT, TEXT)

in order to get a useful result.


And, as you are working on it, don't use os.popen - it is deprecated. 
Better use subprocess:

replace

p = os.popen("%s -t -i" % SENDMAIL, "w")
p.write(message)
status = p.close()

with

import subprocess
sp = subprocess.Popen([SENDMAIL, '-t', '-i'], stdin=subprocess.PIPE)
sp.communicate(message)
status = sp.wait()

giving more flexibility.


HTH,

Thomas

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-09 13:20 -0800
  Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-09 13:25 -0800
    Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-09 20:42 -0800
      Re: This mail never gets delivered. Any ideas why? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-10 05:56 +0000
        Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-09 22:00 -0800
          Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-10 03:19 -0700
          Re: This mail never gets delivered. Any ideas why? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-10 10:37 +0000
            Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-10 11:39 -0700
              Re: This mail never gets delivered. Any ideas why? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2013-03-11 23:34 +0100
                Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-26 01:49 -0700
                Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-26 03:26 -0700
                Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-05-26 13:44 -0700
                Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-05-26 13:48 -0700
                Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-05-26 14:43 -0700
                Re: This mail never gets delivered. Any ideas why? Cameron Simpson <cs@zip.com.au> - 2013-05-27 10:22 +1000
    Re: This mail never gets delivered. Any ideas why? Michael Torrie <torriem@gmail.com> - 2013-03-09 22:07 -0700
      Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-09 21:10 -0800
        Re: This mail never gets delivered. Any ideas why? Michael Torrie <torriem@gmail.com> - 2013-03-10 10:09 -0600
          Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-10 10:53 -0700
            Re: This mail never gets delivered. Any ideas why? Michael Torrie <torriem@gmail.com> - 2013-03-10 20:20 -0600
          Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-10 10:53 -0700
      Re: This mail never gets delivered. Any ideas why? Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-09 21:10 -0800
    Re: This mail never gets delivered. Any ideas why? Chris Angelico <rosuav@gmail.com> - 2013-03-10 09:15 +1100
  Re: This mail never gets delivered. Any ideas why? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2013-03-11 06:25 +0100
    Re: This mail never gets delivered. Any ideas why? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2013-03-11 06:47 +0100
      Re: This mail never gets delivered. Any ideas why? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2013-03-11 06:59 +0100
  Re: This mail never gets delivered. Any ideas why? nagia.retsina@gmail.com - 2013-03-11 02:15 -0700
    Re: This mail never gets delivered. Any ideas why? Benjamin Schollnick <benjamin@schollnick.net> - 2013-03-11 06:44 -0400
    Re: This mail never gets delivered. Any ideas why? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2013-03-11 17:24 +0100

csiph-web