2

recently i'm studing the smtplib smtp client library for python, but i could not find any reference to the PIPELINING protocol against smtp servers that support it. Is there something i'm missing? It's not yet implemented maybe? Any other implementations rather than smtplib with PIPELINING enabled?

Thanks

Wade
  • 3,585
  • 2
  • 22
  • 27
Simone Margaritelli
  • 4,584
  • 10
  • 45
  • 70
  • Why do you want `PIPELINING`? – MattH Sep 14 '10 at 11:30
  • I'm writing an application that needs to send a large amount of emails through my smtp server and i'd like to avoid 1:1 connections overloading the server itself. – Simone Margaritelli Sep 14 '10 at 11:53
  • So your concern is using the same connection for multiple messages? – MattH Sep 14 '10 at 12:14
  • Exactly, i'm starting to think that the pipelining it's not the only way ... :) – Simone Margaritelli Sep 14 '10 at 12:27
  • All SMTP servers allow multiple transactions (MAIL, RCPT, DATA) on the same connection. (In fact, Sendmail has a special command (ONEX) by which you can tell it that you will only have one transaction.) As others have noted, this has nothing to do with pipelining. – james.garriss Jan 14 '13 at 20:23

1 Answers1

7

Is there something i'm missing?

Quite possibly.

Simply put PIPELINING is sending SMTP commands without waiting for the responses. It doesn't tend to be implemented because the benefits are marginal and it increases the complexity of error states.

From your comment, it sounds as if you are worried that only one message will be sent through one connection. This is not PIPELINING.

smtplib supports using the same connection for multiple messages. You can just call sendmail multiple times. E.g.

s = smtplib.SMTP("localhost")
s.sendmail("foo@bar.baz",["bar@foo.baz"],message1)
s.sendmail("foo@bar.baz",["baz@foo.baz"],message2)

Final update

which is the max number of messages i can append "per-connection" ?

This varies between SMTP daemons. Exim seems to default to 1000.

do i have to do this synchronously or does smtplib eventually handle contemporary sendmail calls ?

The call to the sendmail method will block until complete, your calls will be sequential.

If you need to parallelize then you might need to look at threading, multiprocessing or perhaps twisted. There are many possible approaches.

The number of concurrent connections you are allowed may also be an SMTP daemon configuration item.

MattH
  • 37,273
  • 11
  • 82
  • 84
  • Two last things, which is the max number of messages i can append "per-connection" ? And, do i have to do this synchronously or does smtplib eventually handle contemporary sendmail calls ? – Simone Margaritelli Sep 14 '10 at 13:02
  • I know this is eight years later, but for anyone who sees this, the answer to Simone's question is "daemon-configurable". In exim, for instance, it defaults to 1000 (smtp_accept_max_per_connection here: https://www.exim.org/exim-html-current/doc/html/spec_html/ch-main_configuration.html) – A. Wilson Mar 16 '18 at 20:58
  • 1
    @A.Wilson: Not to worry. I'd updated my answer with those details back in 2010. 32 minutes after she posted her followup question. – MattH Mar 16 '18 at 21:01
  • This is what happens when I keep a bunch of SO tabs open for reference and then read them piecemeal later. – A. Wilson Mar 18 '18 at 04:02
  • Hi, Useful answer upvoted. I am facing similar/related problem related to SMTPLIB. Can you please help me here? https://stackoverflow.com/questions/71709672/how-to-send-a-complete-email-using-smtplib-python – The Great Apr 01 '22 at 17:11