Cannot form correctly the FORM part of the header when sending mail

F

Ferrous Cranus

Στις 4/9/2013 7:16 μμ, ο/η Piet van Oostrum έγÏαψε:
Ferrous Cranus said:
I this hoq you mean? [...]

SUBJECT = u"Mail από τον επισκέπτη: ( %s )" % FROM

MESSAGE = "\nFrom: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, [TO], SUBJECT ) + MESSAGE + "\r\n"
MESSAGE = MESSAGE.encode('utf-8') [...]
but now iam getting this error message:

sendmail => %s 13-09-04 12:29:22 (<class 'TypeError'>, TypeError('not all arguments converted during string formatting',), <traceback object at 0x7f0e432e1cb0>)
That is because you changed TO in [TO]. That causes the error.

** And the \n at the beginning shouldn't be there. **

MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, TO, SUBJECT ) + MESSAGE + "\r\n"

You could even change that to:

MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n%s\r\n" % (FROM, TO, SUBJECT, MESSAGE)

which I think is nicer.



Now i have it like you said:


UBJECT = u"SuperHost Guest Mail από τον [ %s ]" % FROM

MESSAGE = "From: %s\n" + "To: %s\n" + "Subject: %s\n\n%s\n" % (FROM, TO,
SUBJECT, MESSAGE)
MESSAGE = MESSAGE.encode('utf-8')


but i still get the same error messgae

i use '\n' though and not '\r\n' but this is not an issue.
 
S

Steven D'Aprano

On Thu, 05 Sep 2013 09:31:41 +0300, Ferrous Cranus wrote:

[...]
UBJECT = u"SuperHost Guest Mail από τον [ %s ]" % FROM

MESSAGE = "From: %s\n" + "To: %s\n" + "Subject: %s\n\n%s\n" % (FROM, TO,
SUBJECT, MESSAGE)
MESSAGE = MESSAGE.encode('utf-8')


but i still get the same error messgae

And? What is the error message telling you? Don't just ask for help every
single time you get an exception. The error says:

TypeError: not all arguments converted during string formatting


What does that mean? The string formatting operator is % and you can, and
should, experiment on it yourself:

py> "aaaa %s" % 'hello'
'aaaa hello'


Now try to get the error you see:

py> "aaaa%s" % ('hello', "world")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting

You have two strings on the right hand side of the % operator, but only
one %s target on the left.

Now how about this?


py> "aa%s" + "bb%s" % ("hello", "world")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting


What's the precedence of + and % operators? Which one gets executed
first? Hint:


py> 8 + 2 % 5
10
py> (8 + 2) % 5
0
py> 8 + (2 % 5)
10

Even though these examples are with ints, not strings, the precedence is
the same.

Go back to your code. Read your code. Does it look closer to this:

8 + 2 % 5

or this?

(8 + 2) % 5


Can you solve this problem now?
 
F

Ferrous Cranus

Even though these examples are with ints, not strings, the precedence is
the same.

Go back to your code. Read your code. Does it look closer to this:

8 + 2 % 5

or this?

(8 + 2) % 5


Can you solve this problem now?

Yes Steven, according to your precedence example now i can:

MESSAGE = ( "From: %s\n" + "To: %s\n" + "Subject: %s\n\n%s\n" ) % (
FROM, TO, SUBJECT, MESSAGE )
MESSAGE = MESSAGE.encode('utf-8')



it just need the whole concatenation thing in parenthesis so to be
executed first but now:


# send the mail
server.sendmail( [ MESSAGE ] )

or

# send the mail
server.sendmail( MESSAGE )

both fail.
 
F

Ferrous Cranus

Στις 5/9/2013 12:34 μμ, ο/η Ferrous Cranus έγÏαψε:
Even though these examples are with ints, not strings, the precedence is
the same.

Go back to your code. Read your code. Does it look closer to this:

8 + 2 % 5

or this?

(8 + 2) % 5


Can you solve this problem now?

Yes Steven, according to your precedence example now i can:

MESSAGE = ( "From: %s\n" + "To: %s\n" + "Subject: %s\n\n%s\n" ) % (
FROM, TO, SUBJECT, MESSAGE )
MESSAGE = MESSAGE.encode('utf-8')



it just need the whole concatenation thing in parenthesis so to be
executed first but now:


# send the mail
server.sendmail( [ MESSAGE ] )

or

# send the mail
server.sendmail( MESSAGE )

both fail.
The error messge says:


(e-mail address removed) [~]# cat /tmp/err.out
sendmail => 13-09-05 12:20:53 (<class 'TypeError'>,
TypeError("sendmail() missing 2 required positional arguments:
'to_addrs' and 'msg'",), <traceback object at 0x7f3fb4f44488>)
(e-mail address removed) [~]#

but all of the needed args are within MESSAGE.
Cant it take it from there?
 
F

Ferrous Cranus

Στις 5/9/2013 1:33 μμ, ο/η Dave Angel έγÏαψε:
(e-mail address removed) [~]# cat /tmp/err.out
sendmail => 13-09-05 12:20:53 (<class 'TypeError'>,
TypeError("sendmail() missing 2 required positional arguments:
'to_addrs' and 'msg'",), <traceback object at 0x7f3fb4f44488>)
(e-mail address removed) [~]#

but all of the needed args are within MESSAGE.
Cant it take it from there?

Do you know how to find a link like this?

http://docs.python.org/3.3/library/smtplib.html#smtplib.SMTP.sendmail
is there way to alter tha FROM field to the one used in the webform by
the visitor?

GMail adds the Sender by default is there some other service that
doesn't and use the FROM field?
 
F

feedthetroll

Am Donnerstag, 5. September 2013 12:48:54 UTC+2 schrieb Ferrous Cranus:
is there way to alter tha FROM field to the one used in the webform by
the visitor?
Yes it ist. You did it in your code.
But gmail alters it AFTER you. So again, you did not care to read / understand the answers you got.
GMail adds the Sender by default is there some other service that
doesn't and use the FROM field?
Yes. Already answered:
Am Mittwoch, 4. September 2013 14:18:55 UTC+2 schrieb Heiko Wundram:
Am 03.09.2013 09:48, schrieb Ferrous Cranus:
Yes, use/setup your own mailserver. Google will not allow you to send
as ("i.e., From:") an arbitrary address besides the one you've
authenticated as.
And again, you did not care to read / understand the answers you got.

So again: You are a troll.
 
F

Ferrous Cranus

Στις 5/9/2013 2:02 μμ, ο/η (e-mail address removed) έγÏαψε:
And again, you did not care to read / understand the answers you got.

So again: You are a troll.

I'm perfectly awra of the answers given to me. I do car to read them and
do care to udnerstand them.

I need information on how to setup my own mail server

i cannot even connect to my 'mail.mydomain.com' mail server like i do
with GMail's.

So:

server = smtplib.SMTP(localhost)

doesn't help, i cannot efen connect to my localhost mail server form
within my script.

An alternative is needed, one that doesnt add up things as Sender but
uses fROM field isntead.
 
F

feedthetroll

Am Donnerstag, 5. September 2013 13:20:23 UTC+2 schrieb Ferrous Cranus:
Στις 5/9/2013 2:02 μμ, ο/η feedthetroll έγÏαψε:

I'm perfectly awra of the answers given to me. I do car to read them and
do care to udnerstand them.

I need information on how to setup my own mail server
i cannot even connect to my 'mail.mydomain.com' mail server like i do
with GMail's.
And you can solve this promblem by asking "How can I change the FROM field with python?" (which was your last question in this context, after you readand understood the cited answers)? ... Good luck!

Beeing serious:
Which mailserver did you install? postfix, exim, sendmail, ...?
Check that and read its dokumentation how to configure authentication.
Then you can use it.
And if you get stuck: A python list is NOT THE RIGHT PLACE to ask questionsabout the configuration of mailservers. Find the correct list for your mailserver and ask there!
So:
server = smtplib.SMTP(localhost)
doesn't help, i cannot efen connect to my localhost mail server form
within my script.
See above.
An alternative is needed, one that doesnt add up things as Sender but
uses fROM field isntead.
No problem. Configure your own mail server the way you want it to work.

But remembering your attitude to security-things it would be better for us if you did NOT adminstrate a mailserver. We do not need another open relay.
 
F

Ferrous Cranus

Στις 5/9/2013 3:18 μμ, ο/η (e-mail address removed) έγÏαψε:
Beeing serious:
Which mailserver did you install? postfix, exim, sendmail, ...?
Check that and read its dokumentation how to configure authentication.
Then you can use it.
And if you get stuck: A python list is NOT THE RIGHT PLACE to ask questions about the configuration of mailservers. Find the correct list for your mailserver and ask there!


My WHM uses DoveCot as enaled mail server but i have no idea how to
setip up to work.

i cannot connect to it via my python script.

i looked over at my WHM for configuration but i didnt find out how to
properly configure it.
 
F

feedthetroll

Am Donnerstag, 5. September 2013 14:36:19 UTC+2 schrieb Ferrous Cranus:
Στις 5/9/2013 3:18 μμ, ο/η feedthetroll έγÏαψε:


My WHM
WHM (http://www.globalacronyms.com/whm):
Meaning of Acronym WHM Language Category
Watt Hour Meter Acronym in English Science, Unit Measure,
Chemistry, Biology, Acronym
Work Hour Management Acronym in English General, Common Abbreviation,
Slang, Acronym
uses DoveCot as enaled mail server but i have no idea how to
setip up to work.
i cannot connect to it via my python script.
OK, I should have been more exact:
To send mails you need a "smtp-server" (MTA - Mail Transfer Agent, Message Transport Agent) like postfix, exim, sendmail, ...

DoveCot is good for "reading" mail (="mailbox management", "pop3(s)", "imap(s)"). You cannot send mails using DoveCot. (You can use a WebMailServiceto access DoveCot for reading and a MTA for sending mails.)

So you have to find out, which MTA you installed (you have root access, don't you) and configure it.

But this is (like so often) becoming extremely offtopic.
i looked over at my WHM for configuration but i didnt find out how to
properly configure it.
http://www.dovecot.org/documentation.html - but DoveCot won't help you here..
 
F

Ferrous Cranus

Στις 5/9/2013 4:29 μμ, ο/η (e-mail address removed) έγÏαψε:
OK, I should have been more exact:
To send mails you need a "smtp-server" (MTA - Mail Transfer Agent, Message Transport Agent) like postfix, exim, sendmail, ...

DoveCot is good for "reading" mail (="mailbox management", "pop3(s)", "imap(s)"). You cannot send mails using DoveCot. (You can use a WebMailService to access DoveCot for reading and a MTA for sending mails.)

So you have to find out, which MTA you installed (you have root access, don't you) and configure it.

But this is (like so often) becoming extremely offtopic.


i as root just inatslled

sendmail and mailx. i have edited the ~/.mailrc to use:


(e-mail address removed) [~/www/cgi-bin]# cat ~/.mailrc
account gmail {
set smtp-use-starttls
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=may)gmail
set smtp-auth-password=my_gmail_pass_not_stupid_enough_to_wite _it_again
}



And now i'm trying to:


cmd = "echo %s | mailx -A gmail -r %s -s %s %s" % (MESSAGE, FROM,
SUBJECT, TO)
p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE )
output, errors = p.communicate()
print( errors, output )


Any ideas please why this fails to work?
while i remove the '-A gmail' string in the cmd line then i can send
fast mail but only to mail containing the @superhost.gr trail.

i need to be eble to send to external mails to.
 
F

Ferrous Cranus

Στις 5/9/2013 4:38 μμ, ο/η Ferrous Cranus έγÏαψε:
Στις 5/9/2013 4:29 μμ, ο/η (e-mail address removed) έγÏαψε:
OK, I should have been more exact:
To send mails you need a "smtp-server" (MTA - Mail Transfer Agent,
Message Transport Agent) like postfix, exim, sendmail, ...

DoveCot is good for "reading" mail (="mailbox management", "pop3(s)",
"imap(s)"). You cannot send mails using DoveCot. (You can use a
WebMailService to access DoveCot for reading and a MTA for sending
mails.)

So you have to find out, which MTA you installed (you have root
access, don't you) and configure it.

But this is (like so often) becoming extremely offtopic.


i as root just inatslled

sendmail and mailx. i have edited the ~/.mailrc to use:


(e-mail address removed) [~/www/cgi-bin]# cat ~/.mailrc
account gmail {
set smtp-use-starttls
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=may)gmail
set smtp-auth-password=my_gmail_pass_not_stupid_enough_to_wite _it_again
}



And now i'm trying to:


cmd = "echo %s | mailx -A gmail -r %s -s %s %s" % (MESSAGE, FROM,
SUBJECT, TO)
p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE )
output, errors = p.communicate()
print( errors, output )


Any ideas please why this fails to work?
while i remove the '-A gmail' string in the cmd line then i can send
fast mail but only to mail containing the @superhost.gr trail.

i need to be eble to send to external mails to.
Missing "nss-config-dir" variable.
.. . . message not sent.
Missing "nss-config-dir" variable.
.. . . message not sent.
Missing "nss-config-dir" variable.
.. . . message not sent.
Missing "nss-config-dir" variable.
.. . . message not sent.
Missing "nss-config-dir" variable.
.. . . message not sent.
Missing "nss-config-dir" variable.
.. . . message not sent.

is what iam receivign as error output
 
F

feedthetroll

Am Donnerstag, 5. September 2013 15:38:25 UTC+2 schrieb Ferrous Cranus:
Στις 5/9/2013 4:29 μμ, ο/η feedthetroll έγÏαψε:
OK, I should have been more exact:
To send mails you need a "smtp-server" (MTA - Mail Transfer Agent,
Message Transport Agent) like postfix, exim, sendmail, ...

DoveCot is good for "reading" mail (="mailbox management", "pop3(s)",
"imap(s)"). You cannot send mails using DoveCot. (You can use a
WebMailService to access DoveCot for reading and a MTA for sending mails..)

So you have to find out, which MTA you installed (you have root access,
don't you) and configure it.

But this is (like so often) becoming extremely offtopic.

i as root just inatslled

sendmail and mailx. i have edited the ~/.mailrc to use:

(e-mail address removed) [~/www/cgi-bin]# cat ~/.mailrc
account gmail {
set smtp-use-starttls
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=may)gmail
set smtp-auth-password=my_gmail_pass_not_stupid_enough_to_wite _it_again
}
Don't use gmail. Gmail is the cause of your problem. As long as you use it (whatever way you use) the problem will persist. USE YOUR SENDMAIL.
And now i'm trying to:
cmd = "echo %s | mailx -A gmail -r %s -s %s %s" % (MESSAGE, FROM,
SUBJECT, TO)
p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE )
output, errors = p.communicate()
print( errors, output )
DONT INVOKE THIS VIA PYTHON. Use the shell. If it works there, you can try it with python.
Any ideas please why this fails to work?
while i remove the '-A gmail' string in the cmd line then i can send
fast mail but only to mail containing the @superhost.gr trail.
i need to be eble to send to external mails to.
THIS IS NOT A SENDMAIL LIST!
Solve your sendmail-problem and then, if it still does not work from pythoncome back with a smart question.

FUP: comp.mail.sendmail
 
P

Piet van Oostrum

Ferrous Cranus said:
it just need the whole concatenation thing in parenthesis so to be
executed first but now:


# send the mail
server.sendmail( [ MESSAGE ] )

or

# send the mail
server.sendmail( MESSAGE )

both fail.

The first thing you should do then is to look up the documentation of
sendmail. http://docs.python.org/ has a good index where you can look
for sendmail.
 
F

Ferrous Cranus

Στις 5/9/2013 6:00 μμ, ο/η (e-mail address removed) έγÏαψε:
Am Donnerstag, 5. September 2013 15:38:25 UTC+2 schrieb Ferrous Cranus:
Στις 5/9/2013 4:29 μμ, ο/η feedthetroll έγÏαψε:
uses DoveCot as enaled mail server but i have no idea how to
setip up to work.
i cannot connect to it via my python script.
OK, I should have been more exact:
To send mails you need a "smtp-server" (MTA - Mail Transfer Agent,
Message Transport Agent) like postfix, exim, sendmail, ...

DoveCot is good for "reading" mail (="mailbox management", "pop3(s)",
"imap(s)"). You cannot send mails using DoveCot. (You can use a
WebMailService to access DoveCot for reading and a MTA for sending mails.)

So you have to find out, which MTA you installed (you have root access,
don't you) and configure it.

But this is (like so often) becoming extremely offtopic.

i as root just inatslled

sendmail and mailx. i have edited the ~/.mailrc to use:

(e-mail address removed) [~/www/cgi-bin]# cat ~/.mailrc
account gmail {
set smtp-use-starttls
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=may)gmail
set smtp-auth-password=my_gmail_pass_not_stupid_enough_to_wite _it_again
}
Don't use gmail. Gmail is the cause of your problem. As long as you use it (whatever way you use) the problem will persist. USE YOUR SENDMAIL.
And now i'm trying to:
cmd = "echo %s | mailx -A gmail -r %s -s %s %s" % (MESSAGE, FROM,
SUBJECT, TO)
p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE )
output, errors = p.communicate()
print( errors, output )
DONT INVOKE THIS VIA PYTHON. Use the shell. If it works there, you can try it with python.
Any ideas please why this fails to work?
while i remove the '-A gmail' string in the cmd line then i can send
fast mail but only to mail containing the @superhost.gr trail.
i need to be eble to send to external mails to.
THIS IS NOT A SENDMAIL LIST!
Solve your sendmail-problem and then, if it still does not work from python come back with a smart question.

FUP: comp.mail.sendmail
pok i will ask to sendmail list

but tell me please mailx and senmail are 2 differnt MTAs or mailx makes
use of sendmail MTA?
 
F

feedthetroll

Am Donnerstag, 5. September 2013 17:59:42 UTC+2 schrieb Ferrous Cranus:
ok i will ask to sendmail list
Take a look at:
but tell me please mailx and senmail are 2 differnt MTAs or mailx makes
use of sendmail MTA?
mailx is a MUA (Mail User Agent) used to read and write mails.
For sending mails it uses the MTA.
 
S

Steven D'Aprano

(e-mail address removed) [~]# cat /tmp/err.out sendmail => 13-09-05 12:20:53
(<class 'TypeError'>, TypeError("sendmail() missing 2 required
positional arguments: 'to_addrs' and 'msg'",), <traceback object at
0x7f3fb4f44488>) (e-mail address removed) [~]#

but all of the needed args are within MESSAGE. Cant it take it from
there?

Obviously not. If it could, it would.
 
S

Steven D'Aprano

but tell me please mailx and senmail are 2 differnt MTAs or mailx makes
use of sendmail MTA?

Nikos, I know you can write English better than that. Are you
deliberately trying to look less intelligent?
 

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,772
Messages
2,569,591
Members
45,102
Latest member
GregoryGri
Top