[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Email Directly from python

byte8bits

2/13/2008 8:19:00 PM

I'd like to send email directly from within python without having to
rely on an external smtp server. You know, something like the good, old
Unix...

echo My_message | mail -s Subject person@someplace.com

Can Python do something similar in a portable fashion without a smtp
server installed on the machine?

Thanks,
Brad
10 Answers

Larry Bates

2/13/2008 8:51:00 PM

0

brad wrote:
> I'd like to send email directly from within python without having to
> rely on an external smtp server. You know, something like the good, old
> Unix...
>
> echo My_message | mail -s Subject person@someplace.com
>
> Can Python do something similar in a portable fashion without a smtp
> server installed on the machine?
>
> Thanks,
> Brad

smtp module can do what you want yes.

-Larry

Martin P. Hellwig

2/13/2008 9:00:00 PM

0

Larry Bates wrote:
> brad wrote:
>> I'd like to send email directly from within python without having to
>> rely on an external smtp server. You know, something like the good,
>> old Unix...
>>
>> echo My_message | mail -s Subject person@someplace.com
>>
>> Can Python do something similar in a portable fashion without a smtp
>> server installed on the machine?
>>
>> Thanks,
>> Brad
>
> smtp module can do what you want yes.
>
> -Larry
The tricky part is how to resolve the mail server for a mail address.
Usually you have to query the mx record of that domain. I solved that by
looking if I can find the nslookup binary.

I already wrote a command line mailer that can do attachments too, no
need to write it again. If anybody is interested I can open-source it.

--
mph

Guilherme Polo

2/13/2008 9:06:00 PM

0

2008/2/13, brad <byte8bits@gmail.com>:
> I'd like to send email directly from within python without having to
> rely on an external smtp server. You know, something like the good, old
> Unix...
>
> echo My_message | mail -s Subject person@someplace.com

I hope to not disappoint you, but mail will invoke a smtp server to
send your mail.

>
> Can Python do something similar in a portable fashion without a smtp
> server installed on the machine?

You can use a smtp server that is installed somewhere else.

>
> Thanks,
> Brad
>
> --
> http://mail.python.org/mailman/listinfo/p...
>


--
-- Guilherme H. Polo Goncalves

byte8bits

2/13/2008 9:11:00 PM

0

Martin P. Hellwig wrote:

> The tricky part is how to resolve the mail server for a mail address.
> Usually you have to query the mx record of that domain. I solved that by
> looking if I can find the nslookup binary.

The from and to are static constants... they don't change. Mail just
seems so tricky these days what with all the blacklists, greylists,
whitelists, etc. It's almost as if email is broken. Location of the
sending pc matters too. Just wondering if there is a super simple one
liner in Python (that's portable) that can do this.

Martin P. Hellwig

2/13/2008 9:15:00 PM

0

brad wrote:
> Martin P. Hellwig wrote:
>
>> The tricky part is how to resolve the mail server for a mail address.
>> Usually you have to query the mx record of that domain. I solved that
>> by looking if I can find the nslookup binary.
>
> The from and to are static constants... they don't change. Mail just
> seems so tricky these days what with all the blacklists, greylists,
> whitelists, etc. It's almost as if email is broken. Location of the
> sending pc matters too. Just wondering if there is a super simple one
> liner in Python (that's portable) that can do this.
>
Well the problem is that you can't control whether the to address won't
be handled with a different mail server in the future. Whether the
receiving party marks your mail as spam or not is actually their
problem. If you act according to the RFC's it should be delivered.
Of course it helps if you don't make the content be spam ;-)

--
mph

Martin P. Hellwig

2/13/2008 9:48:00 PM

0

Martin P. Hellwig wrote:
<cut>
> I already wrote a command line mailer that can do attachments too, no
> need to write it again. If anybody is interested I can open-source it.
>
To reply on my own post ;-)
Even if nobody is interested in case you change your mind it is hosted
at: http://code.google.com/p/c...

Under the new BSD license, even included a stand-alone (py2exe) windows
version for the couple of remaining servers that have no python installed.

The non-compiled version should work on all platforms having a
reasonable new python version and nslookup.

--
mph

Martin P. Hellwig

2/14/2008 1:14:00 AM

0

Guilherme Polo wrote:
<cut>
> I hope to not disappoint you, but mail will invoke a smtp server to
> send your mail.
>
<cut>
I disagree. If you really want to, all you need is telnet. You connect
to port 25 of the mail server that handles the mail of the domain for
that mail address and do the helo, mail from, rcpt to, data stuff.

Mail indeed does invoke a smtp server, but strictly speaking only to
receive it for the user.

--
mph

Dennis Lee Bieber

2/14/2008 8:38:00 AM

0

On Thu, 14 Feb 2008 02:14:03 +0100, "Martin P. Hellwig" <xng@xs4all.nl>
declaimed the following in comp.lang.python:

> Guilherme Polo wrote:
> <cut>
> > I hope to not disappoint you, but mail will invoke a smtp server to
> > send your mail.
> >
> <cut>
> I disagree. If you really want to, all you need is telnet. You connect
> to port 25 of the mail server that handles the mail of the domain for
> that mail address and do the helo, mail from, rcpt to, data stuff.
>
> Mail indeed does invoke a smtp server, but strictly speaking only to
> receive it for the user.

The first response to the query was to invoke the command line
"mail" utility of a Unix type OS. THAT program is, what I believe, was
meant by "mail will invoke a smtp server"... Not "mail" as a general
concept, but the utility command...
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com wulfraed@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-asst@bestiaria.com)
HTTP://www.bestiaria.com/

Martin P. Hellwig

2/14/2008 9:57:00 AM

0

Dennis Lee Bieber wrote:
<cut>
> The first response to the query was to invoke the command line
> "mail" utility of a Unix type OS. THAT program is, what I believe, was
> meant by "mail will invoke a smtp server"... Not "mail" as a general
> concept, but the utility command...

Ah yes I see that now, sorry for the misinterpretation.

--
mph

danfolkes

2/15/2008 10:25:00 PM

0

You could always just set up a gmail account and use that SMTP. Thats
what I do. Then all you have to do is google search for "gmail smtp
python" and get some easy code.

You can even send attatchments really easy.

-Daniel Folkes

brad wrote:
> I'd like to send email directly from within python without having to
> rely on an external smtp server. You know, something like the good, old
> Unix...
>
> echo My_message | mail -s Subject person@someplace.com
>
> Can Python do something similar in a portable fashion without a smtp
> server installed on the machine?
>
> Thanks,
> Brad