- π©πͺGermany zevier
If this module shall be used widely, it needs URGENT more documentation.
The documentation https://www.drupal.org/docs/contributed-modules/symfony-mailer-0/feature... β claims what could be possible, but donβt show and donβt explain.
PLEASE provide some simple examples for basic functionality on level3.
If it is easy as claimed, please show.- - Give a minimal hello_world example what is needed to send an email (on level3 inside of a new module).
- - Give another example with attachment, using of templates etc.
- π³πΏNew Zealand john pitcairn
More on question 6 from comment #7:
For modules (not themes) previously using
hook_preprocess_swiftmailer()
to add css libraries for inlining, what is the equivalent procedure to add a module library and have its css inlined using symfony_mailer? - πͺπ¨Ecuador jwilson3
Unofficial answer, and untested but a few ideas to try:
- Specify which theme you want to use in your policies, eg "mytheme".
- add the "email" library to mymodule.libraries.yml following the instructions in getting started β
- add an empty "email" library to mytheme.libraries.yml with a dependency on
mymodule/email
If that doesnt work (and I'm guessing might not)...
- remove the module library dependency from the theme library, add an empty "css/mail.css" in the theme library.
- alter the theme library using https://api.drupal.org/hook_library_info_alter in mymodule.module to swap out the path to the css file to point to the one from the module folder.
- π³πΏNew Zealand john pitcairn
Argh, I hope not. The theme and module are completely independent of each other. It should be possible for a module to send mail and inline its own css without relying on any theme.
- π©πͺGermany dercheffe Sersheim, Germany
What I need is, how to natively create an email with this module directly. Wi
email_entity = $email_factory->newTypedEmail('MYMODULE', 'my_awsome_email_subtype'); $email_entity->setParam('user_display_name', $user_recipient_name); $email_entity->setSender($email_from); $email_entity->setSubject($email_subject); $email_entity->setTextBody($email_body_plain); $email_entity->setTo($user_recipient_email); $operation_status = $email_entity->send();
Unfortunately it doesn't work.
I get "Call to a member function newTypedEmail() on null"πOr how can I do the "native implementation" in the docs it's called "Level 3" correctly?
- π¬π§United Kingdom adamps
what is the equivalent procedure to add a module library and have its css inlined using symfony_mailer?
This seems to be a completely general Drupal question - how to alter a theme library in a module. Try
hook_library_info_alter()
- π¬π§United Kingdom adamps
how to natively create an email with this module directly
It's a good question- I wrote a page for it: https://www.drupal.org/docs/contributed-modules/symfony-mailer-0/develop... β
- πΊπΈUnited States sah62 US
Am I correct in assuming that some of these instructions are intended for module developers, and some are intended for site administrators? For example, "migrate to the new template" appears to be a developer instruction. There's no GUI for it that I can find so there's nothing I can do as a site administrator, but I understand how a module developer would need to switch if their module is sending email.
I just did some testing with my existing webform configuration in which email with attachments is sent. It still works just fine, without changing anything, after configuring Symfony Mailer (with import of my Swift Mailer settings) and removing the legacy applications.
One last question: at what point can I (or should I?) disable the "Emulate swiftmailer" option as a site administrator?
Thanks again!
- π¬π§United Kingdom adamps
Am I correct in assuming that some of these instructions are intended for module developers, and some are intended for site administrators?
Yes unfortunately it's a bit muddled up, π Improve the documentation Active . I'm a developer not a writerπ.
One last question: at what point can I (or should I?) disable the "Emulate swiftmailer" option as a site administrator?
If you only use the GUI, then I guess you never wrote templates or CSS files. SO it makes no difference to you, you can do it immediately.
- πΊπΈUnited States chipcleary
Thanks @AdamPS for providing Symfony Mailer!
In case it is useful for others, as I played with using Symfony Mailer to create my first custom email using it, I developed a "Hello World" email example module. See here: https://github.com/chipcleary/symfony_mailer_example/blob/main/README.md.
This provides a basic example of how to programmatically define and send custom mail, including:
- Defining a custom EmailBuilder
- Providing and using twig variables
- Providing a mailer policy
- Providing CSS
All of this is already covered in the existing documentation β . But it took me some hunting-and-pecking to identify which parts I needed and how to apply it.
Caveats:
- I'm a novice developer and am unfamiliar with Symfony Mailer. I wrote this as I worked through how to create a first custom email. It's only meant to provide a minimal "starterkit" example. It is emphatically *not* authoritative.
- It does not address either of the two examples used in the issue statement, which are a step more advanced (theming system emails, sending attachments).
- π¬π§United Kingdom adamps
@chipcleary Your example is similar to TestEmailBuilder from this module, but betterπ. I would like to bring the extra parts into here.
- libraries.yml
- CSS file
- A variable - e.g. the date (a bit more 'serious' than a lucky numberπ)
I would welcome a patch.
- πΊπΈUnited States chipcleary
@AdamPS, glad you like it and I'd be happy to provide a patch! I should be able to provide it by the end of the week.
- πΊπΈUnited States chipcleary
@AdamPS, here's a stab at the patch. Happy to make modifications.
I extended the email to include:
- A header and footer, which use custom CSS for formatting.
- A "day" variable which captures day of the week.
To implement this, I modified:
- symfony_mailer.libraries.yml
- TestEmailBuilder.php
- symfony_mailer.mailer_policy.symfony_mailer.test.yml
And I added test.email.css.
- last update
over 1 year ago 4 pass, 2 fail - Status changed to Needs review
over 1 year ago 9:17am 4 May 2023 The last submitted patch, 29: symfony-mailer-extend-test-email-3258208-28.patch, failed testing. View results β
- last update
over 1 year ago 4 pass, 2 fail - last update
over 1 year ago 5 pass - Status changed to Needs work
over 1 year ago 11:03am 6 May 2023 - π¬π§United Kingdom adamps
It's good thanks, please can you just tidy up some details:
1)
TestEmailBuilder
I like that you added clear explanations to help anyone using this file as an example to copy. Please can you avoid splitting a line of code with comments, and instead put the comments first as separate bullet points, then$email->addLibrary('symfony_mailer/test')
. Also check the coding standards, keep to max length 80 characters.2)
symfony_mailer.mailer_policy.symfony_mailer.test.yml
I have made the yml files easy for a human to read, to help people using it as an example. Please keep the syntaxvalue: |-
then use a separate line for each paragraph and, for consistency, keep with the single quotes around the subject.3)
test.email.css
The initial comment should contain a @file annotation and remove the 2 lines with only a star.4) Please add an extra line into
TestEmailTest
to check that one of the styles is present. Use a comment to say the style comes fromtest.email.css
. - Status changed to Needs review
over 1 year ago 5:37pm 6 May 2023 - last update
over 1 year ago 4 pass, 1 fail - πΊπΈUnited States chipcleary
Helpful feedback, thanks. Here's an updated patch. Would you be able to check in particular whether I've addressed #4 appropriately? I'm least confident about that one.
The last submitted patch, 34: symfony-mailer-extend-test-email-3258208-34.patch, failed testing. View results β
- last update
over 1 year ago 5 pass - π¬π§United Kingdom adamps
Great it looks good. I changed it slightly, hopefully it fixes the tests.
-
AdamPS β
committed 0914b808 on 1.x authored by
chipcleary β
Issue #3258208 by chipcleary, AdamPS: Simple examples to show the...
-
AdamPS β
committed 0914b808 on 1.x authored by
chipcleary β
- Status changed to Active
over 1 year ago 5:43pm 7 May 2023 - Status changed to Needs work
over 1 year ago 4:07pm 8 May 2023 - πΊπΈUnited States chipcleary
Super, thanks @AdamPS. Let me know if there's anything else you'd like.
- Status changed to Active
over 1 year ago 4:59pm 10 May 2023 - π¬π§United Kingdom adamps
It's good thanks. I've left the issue open because there's still more that could be done.