When using MIME Mail and SMTP Authentication the output for emails is incorrect.
Email starts off with....
boundary="=_9e927b29a844f2257f15bc0cf0875e3a" --=_9e927b29a844f2257f15bc0cf0875e3a Content-Transfer-Encoding: 8bit Content-Type: text/html; charset=UTF-8
Has the rest of the mail and then...
--=_9e927b29a844f2257f15bc0cf0875e3a Content-Transfer-Encoding: base64 Content-ID: <8376a3e45f72bfd957f7bb16c41fe715> Content-Type: image/png; name=logo.png Content-Disposition: inline; filename=logo.png; size=10205 iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAYAAACI7Fo9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAA GXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAJ2pJREFUeNrsnQl8FdX1x09e9gUS 1oQ9hLAUkIQqoqh/gq1bqyXW9t/SKmAXW2utqC1ufwvWqqW1mlqt1GqN2lZbq0JdqtZKaBUFVBK2 CoQQQtgCgSRkX+A/52XGPkLy5t6ZOzP3zpzf5zMG4b2XeTP3O2e5554bc+LECSAppwL9Z752ZOhH fsS/z7b5+asj/lyqHXX6Uar/XQndArUUQ6BLq2z9KIj4M8KcLsn51evgV+pHScSfSQQ6qQ+o8/Wj
And so on....(the base64 encoded image).
Looks like this problem is related to https://www.drupal.org/node/2786907.
Will investigate and submit patch. I need this functionality.
Comments
Comment #2
monstrfolk commentedComment #3
salvisHmm, what is SMTP Authentication's part in this story?
Your patch from #2786907: Issues related to multipart/alternative email certainly looks reasonable. What makes you think it's the culprit?
I'm a bit less sure about the other patch from #1341772: File attachments, but two people confirmed that it was working.
Is SMTP Authentication futzing with the multipart structure in some way? Why would it do that? If we have to choose whether we can run with or without SMTP Authentication, then we have to choose the latter and ask the other module to look into the issue.
Comment #4
salvisYou're not seeing the #2848309: 500 Error Issues due to $plain issue, are you?
Comment #5
monstrfolk commentedNo 500 errors and I do not think that the the patch I made is the problem. I have been looking at this issue throughout the day and not 100% certain of the problem. I mentioned the other issue because this issue somewhat resembles the same type of issue.
I believe this issue is coming from the combination of Mail Mine with SMTP authentication. Do not see this behavior when STMP authentication is turned off. It could also be from how MailSystem converts the HTML to plain text. That module does some weird stuff I have noticed.
Comment #6
salvisTo check out mailsystem_html_to_text(), you could try to temporarily bypass it by just doing a
return $string;at the top of the function, and then see whether the corruption goes away.Otherwise, would you please take it up with project/smtp?
Comment #7
monstrfolk commentedProblem is with Mail MIME module. You are the maintainer of that module also, is that correct? Should I move this issue to that module?
Comment #8
monstrfolk commentedAt least i think it is.....
Everything goes haywire with the message in Mail MINE at the get function
when it calls
Line 441) $parent_get = parent::get($params, $filename, $skip_head);I don't know if this is because the message is not formatted correctly from HTML Mail or the regex statement in the get function mentioned above.
Comment #9
salvisI can't exactly call myself "maintainer" of these two modules, but I try to keep them afloat by committing patches that are contributed and approved by the community, because I'm the maintainer of Subscriptions and many Subscriptions users rely on these modules.
So, yes, if it's a Mail MIME issue, then please move it over there and we'll continue there.
Comment #10
monstrfolk commentedComment #11
salvisSo SMTP Authentication is not under suspicion anymore, right?
Did this issue pop up after committing #1341772: File attachments? Were you able to attach images before the recent commits to HTML Mail?
Comment #12
monstrfolk commentedI have been investigating more. Images work fine with Mail MIME and no SMTP integration. Not working with SMTP integration. I do not think that the commit is the issue and I had never used this module before. My first interaction with HTML Mail was the day I submitted the patch for the other SMTP error (the boundary/content type).
I am starting to believe that SMTP is the culprit, but am still looking into if this module is properly formatting the message data being sent to SMTP modlue. That module is particular about the exact format of the messages it relays.
The message body has
boundary="=_9e927b29a844f2257f15bc0cf0875e3a" --=_9e927b29a844f2257f15bc0cf0875e3a Content-Transfer-Encoding: 8bit Content-Type: text/html; charset=UTF-8in the data right before calling the mail function in HTMLMailSystem__SmtpMailSystem.mail.inc.Therefore, I still believe this module has something to do with the error. Could you take a look into this at all?
Is the message body supposed to have the boundary and encoding information applied to the front of the message?
Comment #13
salvisNo, I'm sorry, I've never used these modules and don't know how to install and configure them.
Here's how it's supposed to work:
https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
Comment #14
ilopata1@hotmail.com commentedI am experiencing the same issue when using HTML Mail with SMTP Authentication. All works fine with Mime Mail disabled, but enabling it generates corrupted Mime messages -- neither hmtl not plain text can be read correctly.
Comment #15
salvisWould you like to post a good and a bad email message (including all the headers and the MIME structure but without the content)?
Comment #16
spelcheck commentedEdit: This appears to simply be an issue of SMTP module using PHPMailer, and in doing so requires the perfectly formatted MIME generated by Mail MIME to be deconstructed, then sent in parts to PHPMailer. It just doesn't deconstruct nested boundaries correctly, and in turn takes whether nested boundaries within the body of the email, strips the headers and sets it as Content Type: text/html. I don't see these two modules playing nice together. MIME Mail module has a
'Link images only'option to prevent auto-embedding images, but that still leaves us with images the end user needs to download. I'll be creating an issue on SMTP that should address auto-embedding images, but nothing needs to change with Mail MIME. (https://www.drupal.org/project/smtp/issues/1813164#comment-13120306)@salvis, here it is a few years late :P
I'm one of the unfortunate people using HTMLMail (using Mail MIME) and SMTP, hoping to embed images. As a few have stated, the email is delivered is pretty rough shape, displaying a bunch of boundary tags, base64 dumped, etc.
I'm in the early stages of debugging this, but first things first I sent an email through HTMLMail (using Mail MIME)->SMTP, grabbed the source, simplified boundary ids, cids, etc. Then I sent the identical email through PHPMailer itself, then did the same cleaning.
I added linefeeds here and there to each so that when loaded up side-by-side it'll be obvious what is different. I did this because there are some places you can add extra linefeeds, and some places that break the email. Anyways take each of these, save them with an .eml extension and test in your local outlook or whatever you have.
To get the HTMLMail (using Mail MIME)->SMTP email working, I found under
PLAIN MESSAGE HEREI only had to add a semicolon after 'charset=UTF-8', remove the 'Content-Transfer-Encoding: 8bit' line, and indent 'boundary=inner_boundary' with at least a space and remove any linefeeds between it and the line above it.PHPMailer directly (works)
HTMLMail (mimemail) -> SMTP (broken)
The next step is looking in smtp.mail.inc under mailWithoutQueue() function, within
// Processes the message's bodysection. At a glance, it splits the entire email input on the outermost boundary. This leaves us with two body_parts, which it simply looks for 'text/plain' or 'text/html' in each of the parts. It finds 'text/plain' in the first body_part, strips the headers (because PHPMailer automatically sets Content-Type: 'text/plain' for AltBody), then sets it as $mail->AltBody. It then hastily finds 'text/html' in the second body_part, assumes there's nothing else left to be done, strips the headers and sets it as $mail->Body.The problem is that when processing the message's body, it only knows to look for those two things, and it doesn't expect any nesting. It seems we need to do another
_get_substringto get the boundary, and another_boundary_splitto get the inner body_parts, then somehow get those inner body_parts sent to PHPMailer so that it formats correctly. Seeing as the direct PHPMailer email includes everything that's needed for the email to be formatted correctly, I think this is doable.I'll post what I find, but this will at least keep this thread of closing.
Comment #17
spelcheck commentedBetter plan: disable MailMime and instead have SMTP module auto-attach the files directly through PHPMailer, searching for
<img>tags within the body and replacing the urls with corresponding cids used when attaching them withAddEmbeddedImage().The big reason I had MailMime enabled was to auto-embed images through HTMLMail, so might as well handle this within SMTP. Currently with MailMime disabled, HTMLMail sends the entire email as text/html content type, which withing
smtp.mail.incfalls under 'default' in// Processes the message's bodysection. Will create another case for 'text/html', probably looking for<img>srcs that are relative/root-relative, that way the user still has the option of not embedding an image, simply by using an absolute url.Comment #18
spelcheck commentedClosing, because Mail Mime creates perfectly formatted mime encoded emails and handles embedding of images correctly, but when those images are present SMTP module will always destroy those multipart boundaries. SMTP disassembles mime-encoded emails before pushing it back through PHPMailer. As Mail Mime doesn't have an option to disable the embedding of images, it simply will never work upstream of SMTP module when images are present.
If looking to automatically embed local images and get the benefit of HTML formatted emails, alternate options could be using HTML Mail (without Mail Mime) to SMTP module, or Mime Mail (with embedding of images disabled) to SMTP Module.
A patch is available that brings image embedding into SMTP module here: https://www.drupal.org/project/smtp/issues/1813164
Comment #19
salvisThank you very much for following up here and pushing the SMTP issue, spelcheck!
If I understand you correctly, then your SMTP patch should solve this issue, when/if it's committed.
Let's keep this open as support request until there's an SMTP release with the fix.