8 – Swiftmailer prevent composer updates

I have an issue with composer and Drupal 8.9.13. When I try to update Drupal, I always get the next error and I don’t find a way to solve it:

#$> php -d memory_limit=-1 composer.phar update drupal/core --with-dependencies

Loading composer repositories with package information
Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2 is now available and you should upgrade. See https://getcomposer.org/2
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package drupal/swiftmailer (locked at 1.0.0-beta2, required as ^2.0) is satisfiable by drupal/swiftmailer(1.0.0-beta2) but these conflict with your requirements or minimum-stability.
  Problem 2
    - Conclusion: don't install drupal/swiftmailer 2.0.0
    - Conclusion: don't install drupal/swiftmailer 2.0.0-beta1
    - Conclusion: don't install drupal/swiftmailer 2.0.0-alpha2
    - drupal/swiftmailer 2.0.0-alpha1 requires swiftmailer/swiftmailer ~6.1.3 -> satisfiable by swiftmailer/swiftmailer(v6.1.3).
    - Conclusion: don't install swiftmailer/swiftmailer v6.1.3
    - Conclusion: remove swiftmailer/swiftmailer v5.4.12
    - Installation request for drupal/swiftmailer ^2.0 -> satisfiable by drupal/swiftmailer(2.x-dev, 2.0.0-alpha1, 2.0.0-alpha2, 2.0.0-beta1, 2.0.0).
    - Conclusion: don't install swiftmailer/swiftmailer v5.4.12
    - drupal/swiftmailer 2.x-dev requires swiftmailer/swiftmailer ^6.1.3 -> satisfiable by swiftmailer/swiftmailer(6.2.x-dev, v6.1.3, v6.2.0, v6.2.1, v6.2.2, v6.2.3, v6.2.4, v6.2.5, v6.2.6, v6.2.7).
    - Can only install one of: swiftmailer/swiftmailer(6.2.x-dev, v5.4.12).
    - Can only install one of: swiftmailer/swiftmailer(v6.2.0, v5.4.12).
    - Can only install one of: swiftmailer/swiftmailer(v6.2.1, v5.4.12).
    - Can only install one of: swiftmailer/swiftmailer(v6.2.2, v5.4.12).
    - Can only install one of: swiftmailer/swiftmailer(v6.2.3, v5.4.12).
    - Can only install one of: swiftmailer/swiftmailer(v6.2.4, v5.4.12).
    - Can only install one of: swiftmailer/swiftmailer(v6.2.5, v5.4.12).
    - Can only install one of: swiftmailer/swiftmailer(v6.2.6, v5.4.12).
    - Can only install one of: swiftmailer/swiftmailer(v6.2.7, v5.4.12).
    - Installation request for swiftmailer/swiftmailer (locked at v5.4.12) -> satisfiable by swiftmailer/swiftmailer(v5.4.12).

I have updated (manually) switfmailer to 2.0.0 version, and I have changed composer.json to lock it to 2.0.0. But It doesn’t solve the issue. Any suggestion?

8 – How to send send a image inside html email using swiftmailer?

in my Drupal 8 installation I’m using mailsystem module in combination with swiftmailer module. Everything works fine so far, my swiftmailer twig template inside the templates folder of my custom theme is recognized and works as it should in general.

Problem:

When I want to embed a logo inside my template (as inline image), the image can’t be loaded. It renders the template and shows a broken image placeholder. I used the code mentioned in readme.txt (see point 3.2.2) of swiftmailer module:

<img src="https://drupal.stackexchange.com/image:/themes/MYTHEME/logo.png">

Same error when I use

<img src="https://drupal.stackexchange.com/image:{{ base_url }}/themes/MYTHEME/logo.png">

Logo path is generally working, use the same for my theme in general.

The image is embedded also inside the email (using MailHog to check it):

Content-Type: image/png; name=logo.png

Content-Transfer-Encoding: base64

Content-ID: <f8a965e25fc041c5af9318b9d71cd3d1@mysite.site>

Content-Disposition: inline; filename=logo.png

.... image code following ....

How can I get my logo image inside my email correctly?
Would like to avoid simply setting a linked image it to my webserver if possible,to minimize webserver traffic.

Thanks in advance 🙂

8 – Using swiftmailer, how to check if an email was sent successfully?

For example, when Drupal core contact forms fail to send an email for any reason, swiftmailer throws an exception and logs a message. However, I am trying to hook into the process to display appropriate information for my enduser after a contact attempt fail.

For more information drupal contact form does the following to send a message in MessageForm.php:

 $this->mailHandler->sendMailMessages($message, $user);

This trigger the mailManger->mail method which only throws an exception if the mail system had any issues. Here is the relevant code in swiftmailer
Is it possible to determine if the mail failed within the the save method of MessageForm.php?

so far, the only way I could do this is a bit hacky and looks like this.
In my save method of MessageForm.php I’d add:

$email_failed = false;
    $session = Drupal::request()->getSession();
    $errors = $session->getFlashBag()->get('error');
    foreach ($errors as $err_message) {
      if ($err_message->jsonSerialize() === 'An attempt to send an e-mail message failed.') {
        $email_failed = true;
        break;
      }
    }

Change the SMTP settings in SwiftMailer dynamically to send emails with multiple form addresses

Some of your previous answers have not been well received and you run the risk of being blocked from answering.

Please note the following notes exactly:

  • Please be sure answer the question, Enter details and share your research!

But avoid

  • Ask for help, clarification or answering other answers.
  • Make statements based on opinions; secure them with references or personal experiences.

For more information, see our tips for writing great answers.