Skip to content

Support delay in Mailer when using Messenger #36808

Closed
@bobvandevijver

Description

@bobvandevijver

I have an action which imports a list of accounts, each of which will receive an e-mail that the account has been created. Unfortunately, I'm still using SMTP as transport (which is my only option), which means I need to throttle my e-mails. However, I'm using the Mailer component with Messenger (configured with doctrine transport), which means I should be able to something with the scheduled messages.

As far I can see, I have two options for that:

  • Limit the amount of consumed messages by the worker, but also make sure it is not restarted automatically directly after each exit. This would require a more complex worker configuration outside of Symfony to be configured during deployment.
  • Delay the message when putting it on the message bus using the DelayStamp

The latter would have my preference, but unfortunately this is not possible directly with the Mailer as I cannot supply the stamp when calling send. As workaround I can create the SendEmailMessage myself, but as it is marked as internal I obviously really shouldn't.

That's why I propose to add stamp support to the MailerInterface, with default null. When provided while the bus is not configured, it should log a warning (or throw an exception, to be discussed). This way you have more control over the created message, and there are probably some other scenarios where this might be beneficial as well.

Example

/**
 * @throws TransportExceptionInterface
 * @param StampInterface[] $stamps
 */
public function send(RawMessage $message, Envelope $envelope = null, array $stamps = null): void;

Obviously I can make a PR if this is something that is considered to be valuable for the Symfony ecosystem, but I'm looking for input/verification first 😄

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions