This mail never gets delivered. Any ideas why?

  • Thread starter Íßêïò Ãêñ33ê
  • Start date
Í

Íßêïò Ãêñ33ê

SENDMAIL = '/usr/sbin/sendmail'

FROM = mail
TO = ['(e-mail address removed)']
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?
 
Í

Íßêïò Ãêñ33ê

mail = form.getvalue('mail')

id what the user types in an html form and click submits. this can be a non valid email of course i just check if there is a '@' in the mail address.

But will the mail, gets delivered even if mail's value is invalid?
 
C

Chris Angelico

mail = form.getvalue('mail')

id what the user types in an html form and click submits. this can be a non valid email of course i just check if there is a '@' in the mail address..

But will the mail, gets delivered even if mail's value is invalid?

I asked the postman to deliver a letter to Dreaded Batter Pudding
Hurler, Bexhill-on-Sea, England 142857. Will that letter get delivered
even if that address is invalid? Is email in any way magical and able
to deliver mail to invalid values, whatever it is you mean by "value"?

ChrisA
 
M

Michael Torrie

mail = form.getvalue('mail')

id what the user types in an html form and click submits. this can be
a non valid email of course i just check if there is a '@' in the
mail address.

But will the mail, gets delivered even if mail's value is invalid?

Who knows. You haven't specified how you are sending e-mail. Likely, if
an e-mail address is invalid, python still happily hands it off to your
designated mail server or local MTA (mail transfer agent--could be
sendmail). What happens there depends entirely on the policies of the
mail server or MTA you are using.

If python is trying to use sendmail, then probably the process would
just fail and return some sort of error code. But you will need to
check on the documentation of whatever e-mail library you are using in
Python.
 
Í

Íßêïò Ãêñ33ê

Ôç ÊõñéáêÞ, 10 Ìáñôßïõ 2013 7:07:25 ð.ì.. UTC+2, ï ÷ñÞóôçò Michael Torrie Ýãñáøå:
Who knows. You haven't specified how you are sending e-mail. Likely, if

an e-mail address is invalid, python still happily hands it off to your

designated mail server or local MTA (mail transfer agent--could be

sendmail). What happens there depends entirely on the policies of the

mail server or MTA you are using.



If python is trying to use sendmail, then probably the process would

just fail and return some sort of error code. But you will need to

check on the documentation of whatever e-mail library you are using in

Python.

I'am using smtplib and i ahve contacted the hostgator administrators and they say that Sendmail is ebaled for my reseller account.
 
Í

Íßêïò Ãêñ33ê

Ôç ÊõñéáêÞ, 10 Ìáñôßïõ 2013 7:07:25 ð.ì.. UTC+2, ï ÷ñÞóôçò Michael Torrie Ýãñáøå:
Who knows. You haven't specified how you are sending e-mail. Likely, if

an e-mail address is invalid, python still happily hands it off to your

designated mail server or local MTA (mail transfer agent--could be

sendmail). What happens there depends entirely on the policies of the

mail server or MTA you are using.



If python is trying to use sendmail, then probably the process would

just fail and return some sort of error code. But you will need to

check on the documentation of whatever e-mail library you are using in

Python.

I'am using smtplib and i ahve contacted the hostgator administrators and they say that Sendmail is ebaled for my reseller account.
 
S

Steven D'Aprano

Any ideas why the mail never gets delivered?

What do the mail logs say?

Can you send email using this mail server from Thunderbird, or does it
fail there too?

My wild guess is that the mail server is properly rejecting mail because
you are trying to send to it without an account.
 
Í

Íßêïò Ãêñ33ê

Ôç ÊõñéáêÞ, 10 Ìáñôßïõ 2013 7:56:45 ð.ì.. UTC+2, ï ÷ñÞóôçò Steven D'Aprano Ýãñáøå:
My wild guess is that the mail server is properly rejecting mail because
you are trying to send to it without an account.

Account 'support(-at-)hostgator.com' exists. It's the recipient mail address which is my personal address fot my web hosting business.

In TB yes i can read email via SSL witohut any problem.
 
Í

Íßêïò Ãêñ33ê

Anyone else migth ahve an idea please so that i can successfully send mail via python?
 
S

Steven D'Aprano

Τη ΚυÏιακή, 10 ΜαÏτίου 2013 7:56:45 Ï€.μ. UTC+2, ο χÏήστης Steven
D'Aprano έγÏαψε:


Account 'support(-at-)hostgator.com' exists. It's the recipient mail
address which is my personal address fot my web hosting business.

In TB yes i can read email via SSL witohut any problem.


I didn't ask if you can READ email using Thunderbird, I asked if you can
SEND email using Thunderbird, *specifically* sending using the same mail
server as your script is trying to do.

There is no point checking that Thunderbird can send email as
"(e-mail address removed)" using the gmail server. You have to check whether
it can send email as "mail" (notice that it is just a local name, not a
full email address), using /usr/sbin/sendmail on whatever machine you
happen to be using.

A second question... what happens if you try to send email using sendmail
directly from the command line? If this is a hosted server, are you sure
that they have enabled sendmail on the hosted server?

What happens if you try to send email using the email library, as seen
here:

http://docs.python.org/3/library/email-examples.html

instead of using popen to talk directly to sendmail?
 
M

Michael Torrie

I'am using smtplib and i ahve contacted the hostgator administrators
and they say that Sendmail is ebaled for my reseller account.

You need to post the code snippet that's failing (possibly changing
private details like smtp server ip address for security reasons), and
any exception trace that you are getting! Other wise, sorry we've done
all we can.
 
Í

Íßêïò Ãêñ33ê

Ôç ÊõñéáêÞ, 10 Ìáñôßïõ 2013 6:09:53 ì.ì.. UTC+2, ï ÷ñÞóôçò Michael Torrie Ýãñáøå:
You need to post the code snippet that's failing (possibly changing
private details like smtp server ip address for security reasons), and
any exception trace that you are getting! Other wise, sorry we've done
all we can.

Michael may i send you an email with my reseller account password so you can try things for yourself because i'am not sure what exactly i must do in the remote jailed unix prompt ?
 
Í

Íßêïò Ãêñ33ê

Ôç ÊõñéáêÞ, 10 Ìáñôßïõ 2013 6:09:53 ì.ì.. UTC+2, ï ÷ñÞóôçò Michael Torrie Ýãñáøå:
You need to post the code snippet that's failing (possibly changing
private details like smtp server ip address for security reasons), and
any exception trace that you are getting! Other wise, sorry we've done
all we can.

Michael may i send you an email with my reseller account password so you can try things for yourself because i'am not sure what exactly i must do in the remote jailed unix prompt ?
 
M

Michael Torrie

Michael may i send you an email with my reseller account password so
you can try things for yourself because i'am not sure what exactly i
must do in the remote jailed unix prompt ?

It's never a good idea to share that kind of information with folks on
the internet.

Your subject line reads: "this mail never gets delivered." What e-mail?
What code did you use to send this e-mail? What happened? What
exceptions, if any were given.

I know there's a language barrier here, but you definitely make a habit
of not providing us with sufficient details to help you get your code
working.
 
T

Thomas Rachel

Am 09.03.2013 22:20 schrieb Íßêïò Ãêñ33ê:
SENDMAIL = '/usr/sbin/sendmail'

FROM = mail
TO = ['(e-mail address removed)']
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
 
T

Thomas Rachel

Am 11.03.2013 06:25 schrieb Thomas Rachel:
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.

Mine not, at least.

So you should do this:

import email
message = email.message_from_string('')
message.add_header('From', FROM)
message.add_header('To', ", ".join(TO))
# and then

# either
message.add_header('Subject', email.quoprimime.header_encode(SUBJECT))

# or
message.add_header('Subject', email.base64mime.header_encode(SUBJECT))

# Here you should decide upon readability: for Greek text, base64 is
# probably better, while for languages with Latin characters, quopri
# is better because bost characters remain readable.
#
# The difference is
#
# Subject:
=?iso-8859-1?q?=CE=95=CF=80=CE=B9=CE=BA=CE=BF=CE=B9=CE=BD=CF=89=CE=BD=CE?=
# =?iso-8859-1?q?=AF=CE=B1_=CF=80=CE=B9=CE=B8=CE=B1=CE=BD=CE=BF=CF=8D_=CF?=
# =?iso-8859-1?q?=80=CE=B5=CE=BB=CE=AC=CF=84=CE=B7!?=
#
# vs.
#
# Subject:
=?iso-8859-1?b?zpXPgM65zrrOv865zr3Pic69zq/OsSDPgM65zrjOsc69zr/PjSDPgM61zrs=?=
# =?iso-8859-1?b?zqzPhM63IQ==?=
#
#
# If your sender or your recipients have names outside the ASCII area,
# you should quote them as well.


# These are for the text.
message.add_header('MIME-Version', '1.0')
message.add_header('Content-Type', 'text/plain; charset=utf8')
message.add_header('Content-Transfer-Encoding', '8bit')

message.set_payload(TEXT)

# now transform the object into a string:

message = message.as_string()

print message


This message string now can be used for sending.


HTH,

Thomas
 
T

Thomas Rachel

Am 11.03.2013 06:47 schrieb Thomas Rachel:
# either
message.add_header('Subject', email.quoprimime.header_encode(SUBJECT))

# or
message.add_header('Subject', email.base64mime.header_encode(SUBJECT))

Sorry! These were completely wrong.

# either
message.add_header('Subject', email.quoprimime.header_encode(SUBJECT,
charset='utf8'))

# or
message.add_header('Subject', email.base64mime.header_encode(SUBJECT,
charset='utf8'))

should be correct, however.


But be aware that both seem to potentially break the UTF8 surrogates
apart, which in turn confuses at least Thunderbird, so it might not be
the ideal solution.

Maybe you transcode the subject into iso-8859-7 and declare it as such,
if you only have greek characters.

Let's try:

[...]
# and then
# either
enc = email.base64mime.header_encode
# or
enc = email.quoprimime.header_encode

message.add_header('Subject', enc(
SUBJECT.decode('utf8').encode('iso-8859-7'),
charset='iso-8859-7'))

I tried both values for enc(), and both seem to work with the subject
string you provided.


HTH,


Thomas
 
N

nagia.retsina

Thank you Thomas but that simple line as i have it now its capable of sending mail successfully wven with greek letters two in subject or in message variables.

Now need to dad additional extra code for it to work.
 
B

Benjamin Schollnick

Nagia,
Thank you Thomas but that simple line as i have it now its capable of sending mail successfully wven with greek letters two in subject or in message variables.

Now need to dad additional extra code for it to work.

Your code as it is, isn't working. They just sent you several suggestions on why it might not be working, and your not even testing to see if it might work better, or assist in tracking down the problem?

Even if these suggestions were completely unfounded, are they more readable then your existing code? Or more standards compliant?

If you wish to receive help, please at least try to work with the people that are trying to help you.

Otherwise, you'll end up with someone helping you that won't have your best interests in mind.

- Benjamin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top