Invalid smtp data => change timeout time?

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
schgrypt
Forum Newbie
Posts: 17
Joined: Thu Jan 29, 2009 6:34 am

Invalid smtp data => change timeout time?

Post by schgrypt »

Hello everyone,

using v4b4 I thought of automatically switch transport from smtp to mail() in case the message can't be delivered by smtp. Testing it I assumed that wrong smtp login information would be a possible simulation of smtp failure.

I was surprised to see that the script "waited" around 15seconds before returning that the mail couldnt be delivered by smtp. I guess this is the desired behaviour and that there will be good reasons for it, but somehow I don't like it.

Is it possible to set this timeout to a lower value (I'd set it around 1s I guess) or am I trying something stupid anyway and there would be some kind of best practice for my problem? I was alreading reading something on this forum covering similar approaches but not exactly what I was trying to do.

Thank you very much in advance, greetings
xdecock
Forum Commoner
Posts: 37
Joined: Tue Mar 18, 2008 8:16 am

Re: Invalid smtp data => change timeout time?

Post by xdecock »

Swift_Transport_EsmtpTransport::setTimeout ????
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Invalid smtp data => change timeout time?

Post by Chris Corbyn »

What did you actually do? Wrong username and password but correct SMTP server should be almost instant. Wrong SMTP server could cause severe hangs but this is nothing to do with Swift, it's to do with how your network responds to domain name lookups. If domain name resolution takes a long time before deciding the domain does not exist, then you will get a hang.

Could you please elaborate on the actual way in which you did this? Was it username/password based or was it host-based?
schgrypt
Forum Newbie
Posts: 17
Joined: Thu Jan 29, 2009 6:34 am

Re: Invalid smtp data => change timeout time?

Post by schgrypt »

@xdecock: thank you, I will test it as soon as I get home to my working machine :)

@ Chris: I cant tell 100% sure as I dont have access to the code right now, but I was just randomly inserting some values into my configuration, so its very likely I changed the server as well, thank you for your explaination.
schgrypt
Forum Newbie
Posts: 17
Joined: Thu Jan 29, 2009 6:34 am

Re: Invalid smtp data => change timeout time?

Post by schgrypt »

Unfortunately the delay also appears when only the password is wrong.

Code: Select all

Swift_SmtpTransport::newInstance('domain.com', 25)
                ->setUsername('info@domain.com')
                ->setPassword('wrong_password');
The timeout is less, but still around 8-9 seconds.

@xdecock: can you provide me please with some information about this function? I was looking into the manual for v3 but found only something about setTimeout which doesn't seem to work with v4 (or I am using it wrong).

Thank you and greetings
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Invalid smtp data => change timeout time?

Post by Chris Corbyn »

setTimeout() does work in v4. I just haven't documented it yet.

It sounds as though your hang is in the time it takes to connect with the SMTP server. Do you have the details of the server?

Code: Select all

Swift_SmtpTransport::newInstance('domain.com', 25)
                ->setUsername('info@domain.com')
                ->setPassword('wrong_password')
                ->setTimeout(5);
schgrypt
Forum Newbie
Posts: 17
Joined: Thu Jan 29, 2009 6:34 am

Re: Invalid smtp data => change timeout time?

Post by schgrypt »

Chris Corbyn wrote:Ok, I've found what's happening.

This server supports three different ways to authenticate (PLAIN, LOGIN, CRAM-MD5). When you put the wrong username and password the SMTP server hangs for a second or so while it tries to authenticate you... then it fails.

Now, Swift Mailer doesn't give up (by design) if authentication fails using one authentication mechanism. Instead, it tries again using a different one... until it's tried all possible methods and decides it can't authenticate.

In this case that's adding 3-4 seconds overhead since the server is pausing while Swift tries using each of PLAIN, LOGIN and CRAM-MD5. This is not easily avoidable.
Post Reply