Page 1 of 1

Non-blocking SendMail...

Posted: Wed Nov 26, 2008 4:32 pm
by drone
Hello,

I'm currently working on a PHP web portal that has an 'invite a friend' / 'share with a friend' feature. We allow people to bring in contacts from outside services (google, msn, aol etc.) and then allow them to send an invite to these people.

We are using SWIFT right now with Code Igniter (CIgniter shouldn't affect it at all, I just mention for completness). We direct SWIFT to send via the GMAIL SMTP server.
The problem is that the Send process IS a blocking process. With 25 emails, the system can stall 20-45 seconds before moving to the next page, this is definitely not ideal for the impatient, click-happy web-user!

What I'd like to have happen, is for the emails to NOT BLOCK THE USER PROCESS.

I have been considering a proposal to (a) grab all the email address, (b) database them, (c) run a cronjob in the background that sends the emails BUT I want to make sure there isn't a simpler solution that can be achieved with SWIFT. Is there no way to have SWIFT submit the mails into some type of 'outgoing email queue' or to send using a non-blocking method?

I would also like to be able to send email from whatever FROM field I set. T'seems Google's SMTP server does not allow this (I can't make it look like the email is coming from the user who initiated the invite, it must be a gmail account or an account registered/known to gmail)

Apologies if I've mixed something up. I've have not done alot of work with bulk-email & this is my first use of the SWIFT lib.

Thanks in advance,

Ben

Re: Non-blocking SendMail...

Posted: Wed Dec 03, 2008 12:38 pm
by gmorehoudh
GMail may not be the best choice to do what you're trying to do.

If you have a mail transfer agent installed/working on your server, try using Swift_Connection_Sendmail instead. It will spool the messages to a queue for delivery by the MTA by sending them directly to /usr/sbin/sendmail (or whereever your 'sendmail' lives).

Re: Non-blocking SendMail...

Posted: Fri Dec 05, 2008 10:08 pm
by Chris Corbyn
PHP can't multi-thread so you will need to provide another asynchronous mechanism. Your idea of writing the mail to a DB then using cron to send it is what I would advise and also the way this is typically handled.

Re: Non-blocking SendMail...

Posted: Fri Feb 27, 2009 5:00 pm
by pasquallykc
Well, i am somewhat confused...

what is the purpose of swift mailer, if it can not handle sending bulk messages?

Should it not be the case that all emails be stored in a database and processed by a background email job?

Re: Non-blocking SendMail...

Posted: Fri Feb 27, 2009 5:13 pm
by Eran
What swift can do is unrelated to the latency you introduce by using an external server to send mails. If you used your local server sendmail service or even better, a local SMTP gateway, you would have no performance problems with 25-40 emails. Though using a cron is probably best if it grows beyond those numbers.

Re: Non-blocking SendMail...

Posted: Fri Feb 27, 2009 5:19 pm
by BrandonMUS
drone wrote:I would also like to be able to send email from whatever FROM field I set. T'seems Google's SMTP server does not allow this (I can't make it look like the email is coming from the user who initiated the invite, it must be a gmail account or an account registered/known to gmail)
You are correct. Gmail injects "honest headers". I tried using it as the SMTP server for my phone's email accounts and was completely confused why no one ever responded to me ... only to find out that they were all going to another account when they replied :banghead:

Re: Non-blocking SendMail...

Posted: Fri Feb 27, 2009 5:31 pm
by pasquallykc
Ahh yes, that makes sense now.
A cron job is essential really, as no amount of bulk messaging could be ran without success otherwise.

The only question, than... is if smtp failures are inhereintly part of the game... how often should this cron job be ran?
every minute?

if you want any
pytrin wrote:What swift can do is unrelated to the latency you introduce by using an external server to send mails. If you used your local server sendmail service or even better, a local SMTP gateway, you would have no performance problems with 25-40 emails. Though using a cron is probably best if it grows beyond those numbers.

Re: Non-blocking SendMail...

Posted: Fri Feb 27, 2009 5:41 pm
by xdecock
the only way i see this is with a sendQueue & a background queue::treat(); method, it's quite complex to implement, and should be done by various way (access to a page / crontab / bakground cli script / ...)

So, either you implement your own for your own uses, either you wait it to be implemented (altough, in my own opinion it must not be part of swiftmailer by itself), or implement your own and submit paches

I have an implementation of this kind but quite complex to get out of the current application, so it will need some more work if really needed.