Swiftmailer is very slow

Hi,guys i have a problem, when i send some emails i don`t have any problems ,but i want send 1000 emails with swiftmailer , all emails diferent and to people diferent.

	This:




public function SendAll($AMessages)

{

    foreach ($AMessages as $Result)

    {

                Yii::$app->mailer->compose()

                ->setTo($Player->email)

                ->setFrom([Yii::$app->params["adminEmail"] => Yii::$app->params["title"]])

                ->setSubject($Result['Subject'])

                ->setHtmlBody($Result['Content'])

                ->send();

    }

    return 1;

}



My config is so:







 'mailer' => [

            'class' => 'yii\swiftmailer\Mailer',

            'viewPath' => '@common/mail',

   		'transport' =>

            [

                'class'=>'Swift_SmtpTransport',

                'host'=>'smtp.***',

                'username'=>'test@***',

                'password'=>'*******',

                'port'=>'587',

                'encryption'=>'tls'

                ]

        ],



I am doing this with ajax, but this time is too long,more than one minute,are there any solution for this more fast?

This send 500 emails more or less.

if i do not get any solution , i will have to use mailchimp.

PD:[size="2"]no problem with the number of emails sent.[/size]

As I understand it, you are trying to send 500 unique e-mail messages at one time…

And you don’t like that it takes one minute…

If you are using a standard SMTP server setup from a hosting company ( as opposed to a dedicated e-mail company ), that is really not bad.

That is a little over 8 e-mails a second. For each e-mail your server has to connect to the SMTP server, authorize the connection, send the message details and close the connection. Many SMTP servers are not configured to handle a large inrush of messages at one time, and may throttle incoming messages.

MailChimp will not do what you want. It is designed to send the same message to LOTS of people. Probably what you would want to use would be something like Mailchimp’s Mandrill.

The Mandrill website has a page that talks a lot more about this.

http://blog.mandrill.com/making-smtp-fast.html?_ga=1.69434640.1435566823.1452176969

-John

What I would do in your situation is create a mail queue and call it from cron.

Insert your emails into a db table and let your console controller action process it.

You can throttle it in your script in different ways.

For example, you can opt to process the emails in batches of 50…

Ok, thank you very much for the answers,

I thought of something to do,

i will do it and then put it here.

Edit:

I got to the end fix:

i got an account to mandrillapp for send 25.000 emails in a month.

I use ajax with a loading in screen(autoincrement to 100%) and send 2 params:

	-Array with id user.


	-A counter with the num emails send.

In the action find id user in bbdd for get email, in a for() 5 to 5 Ej: 0-5;6-10;11-15 and send response to client and loading increment,it´s perfect.

This delay 3 seconds to send 5 emails,this is 10 minutes to 1000 emails.