Email Directly from python

B

brad

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 (e-mail address removed)

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

Thanks,
Brad
 
L

Larry Bates

brad said:
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 (e-mail address removed)

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
 
M

Martin P. Hellwig

Larry said:
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.
 
G

Guilherme Polo

2008/2/13 said:
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 (e-mail address removed)

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.
 
B

brad

Martin said:
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.
 
M

Martin P. Hellwig

brad said:
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 ;-)
 
M

Martin P. Hellwig

Martin P. Hellwig wrote:
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/curtusmail/

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.
 
M

Martin P. Hellwig

Guilherme Polo wrote:
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.
 
D

Dennis Lee Bieber

Guilherme Polo wrote:

<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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
M

Martin P. Hellwig

Dennis Lee Bieber wrote:
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.
 
D

Daniel Folkes

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
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top