472,137 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,137 software developers and data experts.

How to send E-mail without an external SMTP server ?

Hi,

I just want to send a very simple email from within python.

I think the standard module of smtpd in python can do this, but I
haven't found documents about how to use it after googleing. Are there
any examples of using smtpd ? I'm not an expert,so I need some examples
to learn how to use it.

Or maybe there is a better way to to this?

Thanks.

xiaojf

Oct 16 '06 #1
11 21947

fd********@gmail.com wrote:
Hi,

I just want to send a very simple email from within python.

I think the standard module of smtpd in python can do this, but I
haven't found documents about how to use it after googleing. Are there
any examples of using smtpd ? I'm not an expert,so I need some examples
to learn how to use it.
See standard documentation:

http://docs.python.org/lib/SMTP-example.html

HTH,
Rob

Oct 16 '06 #2


On Oct 15, 10:25 pm, "fdu.xia...@gmail.com" <fdu.xia...@gmail.com>
wrote:
Hi,

I just want to send a very simple email from within python.

I think the standard module of smtpd in python can do this, but I
haven't found documents about how to use it after googleing. Are there
any examples of using smtpd ? I'm not an expert,so I need some examples
to learn how to use it.
smtpd is for relaying mail not for sending. What you need it a dns
toolkit (search cheeseshop) to map domain name to list of incoming mail
servers, and then using stdlib smtplib try to submit the message to
them.
Or maybe there is a better way to to this?
This won't work if you're behind a strict corporate firewall or if ISP
is blocking port 25 outgoing connections. In those cases you _have_ to
use an external mail server.

Oct 16 '06 #3
Rob Wolfe wrote:
fd********@gmail.com wrote:
>Hi,

I just want to send a very simple email from within python.

I think the standard module of smtpd in python can do this, but I
haven't found documents about how to use it after googleing. Are there
any examples of using smtpd ? I'm not an expert,so I need some examples
to learn how to use it.

See standard documentation:

http://docs.python.org/lib/SMTP-example.html

HTH,
Rob

I have read the example and copied the code and save as send.py, then I
run it. Here is the output:
$ python send.py
From: fd********@gmail.com
To: fd********@gmail.com
Enter message, end with ^D (Unix) or ^Z (Windows):
just a test from localhost
Message length is 82
send: 'ehlo [202.127.19.74]\r\n'
reply: '250-WebMail\r\n'
reply: '250 AUTH plain\r\n'
reply: retcode (250); Msg: WebMail
AUTH plain
send: 'mail FROM:<fd********@gmail.com>\r\n'
reply: '502 negative vibes\r\n'
reply: retcode (502); Msg: negative vibes
send: 'rset\r\n'
reply: '502 negative vibes\r\n'
reply: retcode (502); Msg: negative vibes
Traceback (most recent call last):
File "send.py", line 26, in ?
server.sendmail(fromaddr, toaddrs, msg)
File "/usr/lib/python2.4/smtplib.py", line 680, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (502, 'negative vibes', 'fd********@gmail.com')
Do I have to setup a smtp server on my localhost ?

Thanks a lot.

xiaojf

Oct 16 '06 #4

fd********@gmail.com wrote:
Do I have to setup a smtp server on my localhost ?
If I see correctly your smtp server is gmail.com.

HTH,
Rob

Oct 16 '06 #5


On Oct 16, 12:31 am, "fdu.xia...@gmail.com" <fdu.xia...@gmail.com>
wrote:
Rob Wolfe wrote:
fdu.xia...@gmail.com wrote:
Hi,
I just want to send a very simple email from within python.
I think the standard module of smtpd in python can do this, but I
haven't found documents about how to use it after googleing. Are there
any examples of using smtpd ? I'm not an expert,so I need some examples
to learn how to use it.
See standard documentation:
http://docs.python.org/lib/SMTP-example.html
HTH,
RobI have read the example and copied the code and save as send.py, then I
run it. Here is the output:
$ python send.py
From: fdu.xia...@gmail.com
To: fdu.xia...@gmail.com
Enter message, end with ^D (Unix) or ^Z (Windows):
just a test from localhost
Message length is 82
send: 'ehlo [202.127.19.74]\r\n'
reply: '250-WebMail\r\n'
reply: '250 AUTH plain\r\n'
reply: retcode (250); Msg: WebMail
AUTH plain
send: 'mail FROM:<fdu.xia...@gmail.com>\r\n'
reply: '502 negative vibes\r\n'
reply: retcode (502); Msg: negative vibes
send: 'rset\r\n'
reply: '502 negative vibes\r\n'
reply: retcode (502); Msg: negative vibes
Traceback (most recent call last):
File "send.py", line 26, in ?
server.sendmail(fromaddr, toaddrs, msg)
File "/usr/lib/python2.4/smtplib.py", line 680, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (502, 'negative vibes', 'fdu.xia...@gmail.com')

Do I have to setup a smtp server on my localhost ?
You need to use login method
<http://docs.python.org/lib/SMTP-objects.html>. And by the way, the
subject of your message is very confusing, you are posting log where
you're sending email using external server.

Oct 16 '06 #6
Leo Kislov wrote:
>>
Do I have to setup a smtp server on my localhost ?

You need to use login method
<http://docs.python.org/lib/SMTP-objects.html>. And by the way, the
subject of your message is very confusing, you are posting log where
you're sending email using external server.

Thanks.

Yes, I want to find a way to send email without an external smtp server.

According to Rob's reply, I thought this could be implemented as
described in
the example code of "SMTP Example" on
"http://docs.python.org/lib/SMTP-example.html". So I tried the code,
but failed.

Actually I was writing a script that can submit jobs automatically on a
remote server. I should not submit the jobs all at once, because this
will take up all resources of the server. I just want a specified number
of jobs to be running at one time. If one jobs is over, the script
should submit another job. I run the script with nohup, then I logout.
The script will take care of all jobs.

But I have to check the status of the script manually, which is very
inefficient. So I want to be informed automatically by E-mail when all
jobs are done.
It's not safe if I have to use login method explicitly by which I have
to put my username and password in the script. I have also tried the
Unix command 'mail', but without success, either. I could use 'mail' to
send an E-mail to the user on the server, but I couldn't send an E-mail
to an external E-mail server. I realized that it may because the port 25
outgoing connections are blocked, so I gave up. I will have to login
periodically to check the status of the jobs:-(

Anyway, thank you, Rob, and thank you, Leo.

xiaojf
Oct 16 '06 #7


On Oct 16, 2:04 am, "fdu.xia...@gmail.com" <fdu.xia...@gmail.com>
wrote:
It's not safe if I have to use login method explicitly by which I have
to put my username and password in the script. I have also tried the
Unix command 'mail', but without success, either. I could use 'mail' to
send an E-mail to the user on the server, but I couldn't send an E-mail
to an external E-mail server. I realized that it may because the port 25
outgoing connections are blocked, so I gave up. I will have to login
periodically to check the status of the jobs:-(
Using username password is safe as long as you trust system admin, you
just need to make your script readable only to you. Or even better put
the username and password in a separate file. There is also a way to
limit damage in case you don't trust admin, you just need to get auth
token. Start smtp session and set debug level(True), use login method
and see the token:

send: 'AUTH PLAIN <HERE IS THE TOKEN>\r\n'
reply: '235 2.7.0 Accepted\r\n'
reply: retcode (235); Msg: 2.7.0 Accepted

Then put the token in a file readable only to you, and from now on
instead of login() method use docmd('AUTH PLAIN',"<YOUR TOKEN FROM
FILE>). If the token is stolen, the thief can only send mail from your
account but won't be able to login with password.

Oct 16 '06 #8
On 2006-10-16, fd********@gmail.com <fd********@gmail.comwrote:
Yes, I want to find a way to send email without an external smtp server.
If you're not going to use an SMTP server, what sort of server
do you want to use?

--
Grant Edwards grante Yow! Let me do my TRIBUTE
at to FISHNET STOCKINGS...
visi.com
Oct 16 '06 #9
fd********@gmail.com enlightened us with:
Yes, I want to find a way to send email without an external smtp server.
You can't. Use a DNS server to find the MX record of the destination
domain, connect to that SMTP server, then deliver the mail.

Sybren
--
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
Oct 16 '06 #10
On 2006-10-16, Dennis Lee Bieber <wl*****@ix.netcom.comwrote:
On Mon, 16 Oct 2006 17:04:19 +0800, "fd********@gmail.com"
<fd********@gmail.comdeclaimed the following in comp.lang.python:
>>
Yes, I want to find a way to send email without an external smtp server.
You're going to have to hit an SMTPd somewhere along
the route... Many moons ago it was easy to connect directly to
the recipient's mail server (and even easier to grab any
server one could find, to send mail to any address).
But those were smtp servers, so I don't see you the OP could
have accomplished his goal unless you set the wayback machine
to pre-Internet days and use the uucp transport mechanism.
In closing down these "open relays" to block spammers, many
SMTPd's are now configured to accept "outgoing" mail only from
hosts that are part of the local network, and to accept
"incoming" mail only if the recipient is a member of the local
network. Hence, most client programs are now configured to
connect to the local ISP server to relay mail.
That local ISP server is also an smtp server. I haven't heard
of anybody accepting vail via uucp for at least 10 years. I'm
not saying that such hosts don't exist, but that they're pretty
darned rare.

--
Grant Edwards grante Yow! Today, THREE WINOS
at from DETROIT sold me a
visi.com framed photo of TAB HUNTER
before his MAKEOVER!
Oct 16 '06 #11
On 2006-10-16, Sybren Stuvel <sy*******@YOURthirdtower.com.imaginationwrote:
>Yes, I want to find a way to send email without an external
smtp server.

You can't. Use a DNS server to find the MX record of the
destination domain, connect to that SMTP server, then deliver
the mail.
Or, just send it to a relay server for which you have
privledges. Those are the two choices, and both mean using an
SMTP server.

--
Grant Edwards grante Yow! Gibble, Gobble, we
at ACCEPT YOU...
visi.com
Oct 16 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tom Brown | last post: by
3 posts views Thread by nil | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.