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
Non-blocking SendMail...
Moderators: Chris Corbyn, General Moderators
-
gmorehoudh
- Forum Commoner
- Posts: 50
- Joined: Tue Mar 04, 2008 1:49 pm
Re: Non-blocking SendMail...
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).
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).
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Non-blocking SendMail...
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.
-
pasquallykc
- Forum Newbie
- Posts: 2
- Joined: Fri Feb 27, 2009 4:59 pm
Re: Non-blocking SendMail...
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?
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...
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.
-
BrandonMUS
- Forum Newbie
- Posts: 15
- Joined: Mon Nov 10, 2008 9:45 am
Re: Non-blocking SendMail...
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 replieddrone 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)
-
pasquallykc
- Forum Newbie
- Posts: 2
- Joined: Fri Feb 27, 2009 4:59 pm
Re: Non-blocking SendMail...
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
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...
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.
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.