473,379 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 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 22245

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Filip Wtterwulghe | last post by:
Hello, We have a number of VB6 ActiveX applicationmodule(s) that are loaded into a IE6 WebBrowserControl . This WebControl is imbededded into Application X . Now We want to send a message from...
2
by: Tom Brown | last post by:
Hi, I have what seems to be a simple problem. But I can not for the life of me find a way to send an integer over a socket. The send method will only accept strings. Here is what I am trying to...
1
by: Amadej | last post by:
Hello everyone, I'm having some odd problems with a little program I wrote for sending/receiving bytes across the network. I am using synchronous sockets, and it seems that when I send byte...
1
by: Hasan O | last post by:
hi , I have a problem with socket.send mesajlar = Encoding.ASCII.GetBytes("UGIR"); socketResultValue = socket.Send(mesajlar,0,mesajlar.Length, SocketFlags.None); socketResultValue =...
1
by: charlies224 | last post by:
Hi, I am writting a software that requires me to make sure the Num Lock is always on and Caps Lock is always off. First, I know how to detect if Num Lock or Caps Lock is on or off (if...
3
by: growse | last post by:
Right, I've got a 2 c# programs here. Lets call them A and B. My aim is to send a simple string from B to A. A is always running. I've overridden the WndProc method to give me messages that are...
3
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
0
by: Buddy Home | last post by:
There is two examples of code. Example 1. Send and Receive within the same process. Put this code in a console app called SendAndReceive and run the code. using System; using...
1
by: remya1000 | last post by:
how to send a .txt file to a printer. after creating a .txt file i need to send that .txt file to a printer.using vb.net and while sending that file to printer i need to tell, which printer i need...
3
by: nil | last post by:
Hello everyone, I just wanted to develop one web application which allows users to send an SMS to any mobile free of charge or i can say that i want to develop web application like...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.