Mailing List Archive

Sending a mail
Hi.
I want my script to send a mail with a specific subject. I've tried to
import and use the smtplib, but I get the message that it doesn't exist
- maybe it isn't implemented on the server I'm using, and anyway - I
can't specify a subject using the sendmail()-command...
Then I tried to use the os.system like follows:

#!/usr/local/bin/python
import os
text='echo "hello"|mailto posselt@daimi.au.dk -s "important message"'
os.system(text)

This works quite fine in my python interpreter, but not then I put it on
the web. I tried to print out the standardoutput from os.system(text)
and it was 256. Probably my python-server won't allow me to execute that
command or what? I hope that anyone knows some kind of workaround, or
another way to do this???
Best regards
Peter Posselt Vestergaard
Sending a mail [ In reply to ]
Peter Posselt Vestergaard wrote:
>
> I want my script to send a mail with a specific subject. I've tried to
> import and use the smtplib, but I get the message that it doesn't exist

You should really try smtplib since it's portable.

> - maybe it isn't implemented on the server I'm using, and anyway - I
> can't specify a subject using the sendmail()-command...

Read the smptlib docs more carefully. You have to write the whole header
containing From:, Subject: etc. yourself.

> text='echo "hello"|mailto posselt@daimi.au.dk -s "important message"'
> os.system(text)
>
> This works quite fine in my python interpreter, but not then I put it on
> the web.

This depends on your web server's OS and mail installation. Anyway you
have to ask your webmaster how to send e-mail from the shell.

> I tried to print out the standardoutput from os.system(text)
> and it was 256.

Did you really printed stdout? 256 seems to be the return code of the
os.system() call.

Ask your webmaster to install the missing smptlib.

Ciao, Michael.
Sending a mail [ In reply to ]
Peter Posselt Vestergaard wrote:
> #!/usr/local/bin/python
> import os
> text='echo "hello"|mailto posselt@daimi.au.dk -s "important message"'
> os.system(text)
>
> This works quite fine in my python interpreter, but not then I put it on
> the web. I tried to print out the standardoutput from os.system(text)
> and it was 256. Probably my python-server won't allow me to execute that
> command or what?

Although it's possible that mailto cannot be run by a CGI, before I went
that route I would try using an absolute path for mailto in your command
line. CGIs tend to have limited environments so it probably doesn't
have the path to mailto.

moo
----------------------------------------------------------------------
Ron Klatchko - Manager, Advanced Technology Group
UCSF Library and Center for Knowledge Management
ron@library.ucsf.edu