473,396 Members | 2,039 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,396 software developers and data experts.

question about smtplib

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

Oct 3 '05 #1
7 1685
ne*****@xit.net wrote:
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
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 3 '05 #2
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

Oct 3 '05 #3
ne*****@xit.net wrote:
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>

Oct 4 '05 #4
ne*****@xit.net wrote:
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.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Oct 4 '05 #5
>>>>> Tim Roberts <ti**@probo.com> (TR) wrote:
TR> ne*****@xit.net wrote:
cool. so this line
server = smtplib.SMTP(localhost)
is when i connect ?
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.
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Oct 4 '05 #6
thanks for all the help,
got it working ok now, connecting once, sending many.

thanks for the link too.

cheers,
sk

Oct 4 '05 #7
Piet van Oostrum <pi**@cs.uu.nl> wrote:
>> Tim Roberts <ti**@probo.com> (TR) wrote:

TR> ne*****@xit.net wrote:
cool. so this line
server = smtplib.SMTP(localhost)
is when i connect ?

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.


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.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Oct 6 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Garry Hodgson | last post by:
how do i use smtplib to send mail to someone with "cc" to someone else? if i just include the "to" addressees in the call to smtplib.sendmail(), and put the others in the "Cc" header fields, only...
1
by: David Hughes | last post by:
I wonder if anyone can help me resolve this problem. Although my ISP (One and One) provides the facility to run Python 2.2 CGI programs, their technical support people don't seem to have any Python...
6
by: stewart.midwinter | last post by:
I'm having problem with a script that used to work under Win2k but is now broken after an install of WinXP Pro. I can no longer connect to a local mail server. Has anyone else seen this? If so,...
0
by: Tim Williams | last post by:
I have a working SMTP client that I need to add TLS capability to, I absolutely need the client to timeout within a specified time, but when I use the sock.timeout() line it freezes the reading...
12
by: Chris Dewin | last post by:
Hi. I've been thinking about using smtplib to run a mailing list from my website. s = smtplib.SMTP("server") s.sendmail(fromaddress, toaddresess, msg) I know that in this instance, the...
3
by: Van_Gogh | last post by:
Hi, I am learning how to use the smtplib module, but am having some very early problems, maybe because I don't understand it. So, am I correct that by following the example in the Python: >>>...
0
by: Roger | last post by:
I am having a problem sending email through smtp.gmail.com using smtplib. Everything works and the mail is sent and received, except quit. The following shows the problem (without bothering to...
5
by: zxo102 | last post by:
Hi, I am trying to use python module smtplib to send my email out on window xp (localhost). import smtplib server = smtplib.SMTP('localhost') but I got the error information as follows: ...
1
by: Hunter | last post by:
I am writing a script that needs to send some emails. And I've used smtplib in the past and it is pretty easy. But I thought, gee it would be easier if I could just call it as a function, passing...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.