magepal / magento2-gmail-smtp-app

Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers
https://www.magepal.com
319 stars 148 forks source link

Email message is not visible...but it is attached! #165

Closed shinesoftware closed 4 years ago

shinesoftware commented 4 years ago

Magento version #:

2.3.4

Edition (EE, CE, OS, etc):

CE

Expected behavior:

Read the email message content

Actual behavior:

After the last update the text message content is hidden and a file (attachment.html) is attached to the email as shown in the image.

Steps to reproduce:

Run the test and check the Hello from MagePal SMTP (2 of 2)

Selezione_023

srenon commented 4 years ago

I'm not able to reproduce this issue using Magento 2.3.4 (with Gmail), so this would require further debugging

image

shinesoftware commented 4 years ago

Yes it is really weird! I have a different behaviour in local enviroment and in the production enviroment. Do you have a clue? Why the test sends two messages? which is the differences between them?

shinesoftware commented 4 years ago

I am debugging the code and I have discovered this weird behavior using your module. Check the image. Selezione_024

shinesoftware commented 4 years ago

After a little debug I have noticed that the composer version v2.7.1 generates the issue that I have posted here. After the installation by a simple copy of the module in the "app" directory I can receive the message email correctly. The version installed is the 1.5.1. Any clue?

Selezione_025

The issue is related the UTF8 encoding of the message set in the latest version of the module. Seems that the encoding breaks the message structure and the email client shows it as mentioned before, as attachment.

Index: app/code/MagePal/GmailSmtpApp/Model/ZendMailTwo/Smtp.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/code/MagePal/GmailSmtpApp/Model/ZendMailTwo/Smtp.php    (date 1585125800626)
+++ app/code/MagePal/GmailSmtpApp/Model/ZendMailTwo/Smtp.php    (date 1585125800626)
@@ -86,7 +86,6 @@
        * Temporary fix since 2.2.x will be deprecated shortly and 2.3.3 uses new logic.
        */
        $message = Message::fromString($message->toString());
-        $message->setEncoding('utf-8');

        //Set reply-to path
        switch ($dataHelper->getConfigSetReturnPath()) {
@@ -174,10 +173,6 @@
        try {
            $transport = new SmtpTransport();
            $transport->setOptions($options);
-            $message->getHeaders()->get('to')->setEncoding('utf-8');
-            $message->getHeaders()->get('reply-to')->setEncoding('utf-8');
-            $message->getHeaders()->get('from')->setEncoding('utf-8');
-            $message->getHeaders()->setEncoding('utf-8');
            $transport->send($message);
        } catch (Exception $e) {
            throw new MailException(

... maybe you have to describe why you force the code to use the utf8. please review the file with a better solution.

    /*
     * Fix new encoding issue introduce in 2.2.10 with Amazon SES
     * Temporary fix since 2.2.x will be deprecated shortly and 2.3.3 uses new logic.
     */

With this patch the module works like a charm!

jamie-selesti commented 4 years ago

I am not sure if the issue I have just raised is related https://github.com/magepal/magento2-gmail-smtp-app/issues/166

shinesoftware commented 4 years ago

I am not sure if the issue I have just raised is related #166

No because we have not that error:

PHP Fatal error: Uncaught Error: Call to a member function setEncoding() on bool in /var/www/vhosts/domain.com/vendor/magepal/magento2-gmailsmtpapp/Model/TwoDotThree/Smtp.php

mentioned at https://github.com/magepal/magento2-gmail-smtp-app/issues/166

srenon commented 4 years ago

This issue should be fixed in 2.8.0 which will be released shortly

srenon commented 4 years ago

@shinesoftware ... what email client (webmail, Mac Mail, Thunderbird, Outlook etc) are you using?

Please download 2.8.0 and let me know if you are still having issues

shinesoftware commented 4 years ago

I am using the zoho.eu mail server. I'll check your latest version asap!

shinesoftware commented 4 years ago

Please download 2.8.0 and let me know if you are still having issues

@srenon the dev-master alias 2.8.0 works! Thanks guys!