简体   繁体   English

Symfony 将多封邮件合二为一发送

[英]Symfony group multiple emails into one and send it

I am using Symfony 5.2 and messenger with sengrid for sending mails.我正在使用 Symfony 5.2 和带有 sengrid 的信使来发送邮件。

I want to send an email when a specific action is taken.我想在执行特定操作时发送 email。 But this action can be repeated several times in a row and I don't want to spam my users.但是这个动作可以连续重复几次,我不想向我的用户发送垃圾邮件。 I would like to store these emails before sending, and run a CRON every hour.我想在发送之前存储这些电子邮件,并每小时运行一次 CRON。 CRON would group into a single email if emails are intended for the same users and send them.如果电子邮件是针对同一用户并发送的,CRON 将分组为单个 email。 I wish to know the best method to do this.我想知道最好的方法来做到这一点。

I specify that the easiest way is to create a dedicated table at the base but I wonder if there is not a better method with symfony我指定最简单的方法是在基础上创建一个专用表,但我想知道 symfony 是否没有更好的方法

PS: Sorry for my english PS:对不起我的英语

Thank you in advance.先感谢您。

I don't know what kind of message broker you use, but with RabbitMQ you can do something like:我不知道您使用哪种消息代理,但是使用 RabbitMQ 您可以执行以下操作:

  • Consume a message使用消息
  • Consume an another message, if it's the same action: redo this to the next message, else requeue it and do something with yours messages使用另一条消息,如果它是相同的操作:重做下一条消息,否则重新排队并用你的消息做一些事情

It's a way to group a lot of message easily.这是一种轻松分组大量消息的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM