PreviousNext: Handling Emails Asynchronously: Integrating Symfony Mailer and Messenger
Take advantage of Symfony Mailer’s first-class integration with Symfony Messenger brought to Drupal via the SM project, allowing your site to send emails asynchronously.
This post is part 6 in a series about Symfony Messenger.
- Introducing Symfony Messenger integrations with Drupal
- Symfony Messenger’ message and message handlers, and comparison with @QueueWorker
- Real-time: Symfony Messenger’ Consume command and prioritised messages
- Automatic message scheduling and replacing hook_cron
- Adding real-time processing to QueueWorker plugins
- Making Symfony Mailer asynchronous: integration with Symfony Messenger
- Displaying notifications when Symfony Messenger messages are processed
- Future of Symfony Messenger in Drupal
Since Swift Mailer and its Drupal contrib integration were recently deprecated, many projects have naturally switched to its replacement: Symfony Mailer, either via Drupal Symfony Mailer or Drupal Symfony Mailer Lite.
This post outlines how you can take advantage of Symfony Mailer’s first class integration with Symfony Messenger brought to Drupal via the SM project. This integration allows for dispatching emails off-thread, potentially improving performance of the dispatching (usually web-) thread by offloading email-related tasks to dedicated Symfony Messenger workers. This setup can be considered an alternative to using Queue Mail.
Setup
As of writing, of the two Symfony Mailer implementations in contrib, Drupal Symfony Mailer Lite has built in support for Symfony Messenger. Drupal Symfony Mailer does not yet support it, an issue and merge request exist to add it. Apply a patch until the changes are merged.
Symfony Messenger itself does not require any special configuration, other than installing SM.
To run asynchronously, the SymfonyComponentMailerMessengerSendEmailMessage
message must have routing configuration to a transport. Or at least the fallback transport must be configured. Without transport configuration, Emails will still be dispatched through Messenger, however they will be executed synchronously in the same thread they were dispatched.
Opting out
If you happen to have both Symfony Mailer and Symfony Messenger installed but do not want emails to be sent asynchronously, you can configure routing for the SymfonyComponentMailerMessengerSendEmailMessage
message to instead use the synchronous
transport.
If you’re using the SM Config submodule:
Sending emails and dispatching emails
Emails may be dispatched using the usual Drupal mechanism, or you can dispatch using Symfony Mailer directly by constructing an email object:
$email = (new SymfonyComponentMimeEmail())
->to('jane@example.com')
->from('john@example.com')
->subject('Hello world!')
->text('Some sample text.')
->html('<p>some <strong>sample</strong> text.</p>');
/** @var SymfonyComponentMailerMailerInterface $mailer */
$mailer = Drupal::service(SymfonyComponentMailerMailerInterface::class);
$mailer->send($email);
After the send
method is executed, Mailer checks Messenger is available, creates a new SendEmailMessage
message to wrap the SymfonyComponentMimeEmail
object. Then dispatches SendEmailMessage
to the messenger bus.
As is typical with Symfony Messenger, email messages must be serialisable. Avoid including any Drupal entities or service references in an email object, and render email contents before sending it.
Processing emails
To process email messages, run the worker with sm messenger:consume
. This command will either listen or poll for messages and execute them in a dedicated thread, ensuring quick processing after they are dispatched. For more information on the worker, please refer to post 3 of this series.
In the next post, we’ll explore how to add a user interface to notify users when relevant tasks have been processed.
Tagged
MissionControl::Servers (Resource monitor)
Python 3.12.2 and 3.11.8 are now available.
Python 3.12.2
https://www.python.org/downloads/release/python-3122/
security fix and the usual slew of bug fixes, build changes and
documentation updates (more than 350 commits), this is also the first
release to include a Software Bill-of-Materials for the source packages (Python-3.12.2.tgz and Python-3.12.2.tar.xz). Full changelog.
Python 3.11.8
https://www.python.org/downloads/release/python-3118/
We hope you enjoy the new releases!
and these releases possible! Please consider supporting our efforts by
volunteering yourself, or through contributions to the Python Software Foundation or CPython itself.
on behalf of your release team,
Pablo Galindo Salgado
Łukasz Langa
At FOSDEM
FOSDEM (Free and Open source Software Developers’ European Meeting) is a
non-commercial, volunteer-organized meeting where almost ten thousand people
come together around free and open-source software development. It is aimed
at developers and anyone interested in the free and open-source software
movement. It really is totally open, anyone can just walk up and attend
anything. There is no registration even. And yet, it is full of people who
are central to so many key free software projects that power the world we
live in.
For me personally, FOSDEM was good and intense as usual. I went to FOSDEM
for the first time about five years ago. At that time, when I told people I
worked on F-Droid, they asked, “What’s that?”. I went last year, and when I
said F-Droid, people mostly responded, “oh yeah, nice project!” This year,
it felt like most people’s response was to show me F-Droid installed on
their phone then to thank me. It was really a wonderful confirmation to
receive, especially in person, and was a great reminder that we are
positively affecting people’s lives, although our day-to-day experience is
mostly dealing with the problems that people report.
I’ve been doing free software so long (30 years this year!) that it was hard
for me to walk 50m without running into someone that I should discuss
something with. I talked with people from Debian,
Codeberg, CalyxOS, Clean
Insights, Weblate, The
European Commission, Tella,
Replicant, LineageOS,
OpenJDK, /e/ foundation,
FSFE, EDRi,
Guix, Reproducible
Builds,
Huridocs, WolfSSL,
Internews
SUSTAIN,
OpenWISP, OnionShare,
Mailvelope, Butter,
Thunderbird, Eclipse Foundation and more.
One thing that is particularly impressive is the project
stands. Basically every one of them was
staffed by core contributors. Many founders and project leaders were even at
the stands answering questions from whoever walked up (Mastodon, Calyx,
NLnet, ISRG/Let’s Encrypt, Open Source Design, Codeberg, Thunderbird,
Matrix and more).
EU Legislation and Free Software
For me, the biggest part was the Open Source In The European Legislative
Landscape devroom.
There were a number of people from the European Commission actively engaging
with the hackers like me to understand free software in the context of the
Digital Markets Act, the Cyber Resiliency Act, and the Product Liability
Directive. It was great to see that they are generally supportive of our
point of view. The Digital Markets Act is shaping up to be a powerful tool
for opening up things for free software. The key question now is whether
the European Commission will step up to strongly enforce it in the face of
well-funded attacks from Big Tech.
From that experience, I now feel that the current state of the EU’s Cyber
Resiliency Act (CRA) and the Product Liability Directive (PLD) should not
negatively affect F-Droid or its contributors. I am not a lawyer, so this is
based on my understanding after lots of discussions with people who know a
lot of about it. This is my current understanding of why F-Droid and anyone
who contributes to it should not have to change what they are doing:
- The F-Droid legal entity makes the “product” so it would be liable.
- F-Droid is currently entirely non-commercial, handles no money, and only
commercial activity is regulated by CRA and PLD. - Volunteer contributors are very clearly exempt since all their activity is
non-commercial. - Donation-funded contributions like our
Liberapay should also not be affected
since donations are not paying for a product. - Contracted contributors are helping build the regulated product, so the
legal entities of the contractors would not be liable for F-Droid’s
“product”.
All in all, I enjoyed FOSDEM very much and found it an amazing place to
exchange with other free software projects. The only downside were the
crowds when trying to get food and drink, and the Wi-Fi and cellular
networks being overwhelmed. I can recommend bringing a spare sandwich and a
water bottle. I hope that the F-Droid community can be better represented
there in the future, and I’ll work on that myself to help make it happen.
Hope to see you at FOSDEM!
Open Source AI Definition: Where it stands and what’s ahead
A review of the actions taken toward establishing an Open Source AI Definition and a roadmap of the work to be done in 2024 to get to v. 1.0. Read this recap to stay in the know.
The post <span class=’p-name’>Open Source AI Definition: Where it stands and what’s ahead</span> appeared first on Voices of Open Source.
What is B-right/V release 4.5?
Ong 2023! Rezeki Firdaus Rahmat & Danial Kifli Meledak Tahun Lepas Angkara… | Motif Trending
Video by via Dailymotion Source Top 5 Lagu/Audio Tergempak Gempak Most Wanted Awards 2023, Firdaus Rahmat & Danial Kifli tak sangka lagu mereka menjadi siulan sepanjang 2023. Pernah putus asa, tapi kini mereka TERPALING TRENDING! Gempak Most Wanted️ Setiap Isnin hingga Jumaat⏰ 11 malam Astro Ria dan Astro GO Undi calon fav di gempak.com/gempakmostwanted ASTRO…
Flutter BLOC State Management | BLOC with Firebase 2024 | Introduction Video
Video by via Dailymotion Source Assalam O Alaikum Everyone,This is the Introduction Video of our latest Course #FlutterBlocStateManagement #BlocStatmanagement #flutter #FlutterSmashers Hit the like button and share this video if you find this video helpful ———————————————————– ► Flutter Basics: https://www.youtube.com/watch?v=PDZ4a2VGrk0&list=PLJVa24zVa2o-QSAkv8OYGtSUcDpdbQ8hN&ab_channel=FlutterSmashers ► Visit website: https://fluttersmashers.co/ ———————————————————–►► For Custom Application Order ☑️ ► Upwork: https://bit.ly/3CYXW4S► Fiverr: https://bit.ly/3wbxAbY…