question about smtplib

N

nephish

Hey there,

i am using the smtplib module in python 2.3

my question is, this works:

server = smtplib.SMTP(localhost)

then server.sendmail(to address, from address, message)


what i want to know is, how does the connection work?

when i do server.sendmail, does it connect then ? or did it connect
when
i made the object ?

the reason i need to know is i need to send several emails out at once
and would be best to only connect once, i think.

i know that i can call server.close(), i just dont know when it was
opened.
thanks
 
S

Steve Holden

Hey there,

i am using the smtplib module in python 2.3

my question is, this works:

server = smtplib.SMTP(localhost)

then server.sendmail(to address, from address, message)


what i want to know is, how does the connection work?

when i do server.sendmail, does it connect then ? or did it connect
when
i made the object ?

the reason i need to know is i need to send several emails out at once
and would be best to only connect once, i think.

i know that i can call server.close(), i just dont know when it was
opened.
thanks
If you provide the host name the server is connected immediately. You
can use that connection to send several emails, terminating the
connection when you call the object's quit() method.

regards
Steve
 
N

nephish

cool. so this line
server = smtplib.SMTP(localhost)
is when i connect ?

i had my syntax wrong anyway, i was using server.close()
instead of server.quit()

thanks much
 
F

Fredrik Lundh

cool. so this line
server = smtplib.SMTP(localhost)
is when i connect ?

http://www.python.org/doc/lib/module-smtplib.html

"If the optional host and port parameters are given, the
SMTP connect() method is called with those parameters
during initialization."

"For normal use, you should only require the initialization/
connect, sendmail(), and quit() methods. An example is
included below."

</F>
 
T

Tim Roberts

cool. so this line
server = smtplib.SMTP(localhost)
is when i connect ?

Use the source, Luke. Source code for every standard module is included on
your hard disk. If you look in the __init__ for "class SMTP", your
question will be answered.
 
P

Piet van Oostrum

TR> Use the source, Luke. Source code for every standard module is included on
TR> your hard disk. If you look in the __init__ for "class SMTP", your
TR> question will be answered.

The documentation should be the ultimate reference for the API. The source
is just implementation detail which may change in the future.
 
N

nephish

thanks for all the help,
got it working ok now, connecting once, sending many.

thanks for the link too.

cheers,
sk
 
T

Tim Roberts

Piet van Oostrum said:
The documentation should be the ultimate reference for the API. The source
is just implementation detail which may change in the future.

I won't argue with that, but the question of "exactly when does the
connection occur" is in itself an implementation detail. I wouldn't expect
it to be answered in the documentation.
 

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
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top