Fast mail is sent to the queue for subsequent delivery

When using http://swiftmailer.org, I can send a message to the mail queue so that php returns immediately instead of actually sending the message right now

+6
source share
3 answers

This is an old question, but since it appeared in my Google search, I will answer it with what I understand.

YES! Swiftmailer has the ability to write to reel instead of sending right away. The implementation is pretty simple:

$spool = new Swift_FileSpool('/where/you/want/your/spool'); $transport = Swift_SpoolTransport::newInstance($spool); $mailer = Swift_Mailer::newInstance($transport); 

This says that swiftmailer writes messages to disk and then sends them. Then, using a cron job or other trigger, send messages using something like:

 $spool = new Swift_FileSpool('/where/you/put/your/spool'); $spool_transport = Swift_SpoolTransport::newInstance($spool); // Create the smtp transport. $smtp_transport = Swift_SmtpTransport::newInstance('your.smtp.host', 25); // Get the messages from the spool $spool = $spool_transport->getSpool(); // Send the messages via the real transport. $sent = $spool->flushQueue($smtp_transport); 
+5
source

You can not. swiftmailer / php doesn’t actually deliver mail to you, they just pass it to the SMTP server, and the THAT server delivers for you. You will need to tell SMTP not to process the outbound queue to β€œstop” delivery.

In the real world, swift / php just go to the corner and drop the envelope into the mailbox. A mail truck appears immediately after that and begins the process of sending mail along the way through the mail system. But this is completely out of the PHP view.

+1
source

If you use the sendmail transport, it should return immediately.

From https://github.com/swiftmailer/swiftmailer/blob/4.1/doc/sending.rst :

Typically, the sendmail process will respond quickly because it sends messages to disk before sending them.

You can also see buffering: http://symfony.com/doc/current/cookbook/email/spool.html

0
source

Source: https://habr.com/ru/post/907067/


All Articles