Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty mail body #17

Closed
tutench opened this issue Feb 16, 2017 · 9 comments
Closed

Empty mail body #17

tutench opened this issue Feb 16, 2017 · 9 comments

Comments

@tutench
Copy link

tutench commented Feb 16, 2017

When I create a new user the DokuWiki sents out a mail with the password info but the mail body is completely empty... The same happens when I get a notification about a changed article.

Release 2016-06-26a "Elenor of Tsort"
SMTP Server is an Exchange Server 2013

With the SwiftMailer Plugin everything works fine

If more information is needed, let me know.

@Japanuspus
Copy link

I am seeing the same issue: Using the SMTP plugin I will get an email, but the body is empty, both when using the SMTP test page in the admin panel, and when using any other email feature (password reset, etc.).

I am using an in-house exchange server with no authorization.
The same server is also mentioned in this forum thread where the problem also has been reported and analyzed: https://forum.dokuwiki.org/post/56370).
In the forum thread, the problem was resolved by changing email server, but this option is not open to me.

I can also reproduce the debug trail from the forum thread. This indicates that the advise_before-hook called on line 689 of Mailer.class.php does not return true:
Modifying this file as follows:

// do our thing if BEFORE hook approves
$evt = new Doku_Event('MAIL_MESSAGE_SEND', $data);
echo "<hr>J1 - Before Hook ".$this->text;
if($evt->advise_before(true)) {
    echo "<hr>J2 - Inside hook".$this->text;
    // clean up before using the headers
    $this->cleanHeaders();
    . . .
}
echo "<hr>J3 - After Hook ".$this->text;

I get the following output when trying to send email (from admin test panel):

<hr>J1 - Before Hook Hi jawes

This is a test from http://csi00774/
-- 
This mail was generated by DokuWiki at
http://csi00774/
<hr>J3 - After Hook Hi jawes

This is a test from http://csi00774/
-- 
This mail was generated by DokuWiki at
http://csi00774/

Note that J2 is missing.
Please let me know if there is anything I can do to debug.

SMTP plugin, Installed version: 2017-02-08
DokuWiki: Release 2017-02-19b "Frusterick Manners"

@jkbha
Copy link

jkbha commented May 20, 2017

This seems to be a bug in the way Exchange server is interpreting the mail. Apparently, (some) Exchange servers is not happy with a single end of line character between header and body, but requires TWO (see e.g. https://www.hmailserver.com/forum/viewtopic.php?t=7456 ).

While this is most likely a problem on the Exchange server's side, it should be easy to fix in the next update of the plugin by including an extra blank line between header and body.

@pierpower
Copy link

pierpower commented May 31, 2017

Hello, I've looked into the issue and found that, after the "Content-Transfer-Encoding: base64" string, there is no carriage return (\r), but only 2 line feed chars (\n).

So, I've added the missing carriage return with the following patch in the "toString()" function inside classes\Message.php:

    public function toString() {
    // we need to remove the BCC header here
    $lines = explode("\n", $this->body);
    $count = count($lines);
    for($i=0; $i<$count; $i++) {
        if(trim($lines[$i]) === '') break; // end of headers, we're done
        if(substr($lines[$i],0, 4) == 'Bcc:') {
            unset($lines[$i]); // we found the Bcc: header and remove it
            while(substr($lines[++$i],0, 1) === ' ') {
                unset($lines[$i]); // indented lines are header continuiation
            }
            break; // header removed, we're done
        }
    }
   ////-------------------------------PATCH START--------------------------------////
    //need to add a carriage return after "base64"
	for($i=0; $i<$count; $i++) {
		$pos = strpos($lines[$i],'base64');
        if($pos!=FALSE) {
            $lines[$i] .= "\r"; 
            }
    }
    ////-------------------------------PATCH END--------------------------------////

    $body = join("\n", $lines);

    return $body . $this->CRLF . $this->CRLF . "." . $this->CRLF;
}

I'm not sure if this is the best way to do that, but it works on my installation.

SMTP server : Exchange server.
SMTP plugin, Installed version: 2017-02-08
DokuWiki: Release 2017-02-19b "Frusterick Manners"

Hope that helps.

@Netand1
Copy link

Netand1 commented Jul 4, 2017

Ok UNIX problem ..you need to put : \r in line 88 ( $body = join("\r\n", $lines);) of /site/lib/plugins/smtp/classes/message.php

@lpagie
Copy link

lpagie commented Jan 5, 2018

I followed suggestions in https://forum.dokuwiki.org/thread/14686 which solved the issue for me. Also adds a blank line after the header but in slightly different way.
from thread:

A hacky workaround is to include a line like :
$body = str_replace("base64", "base64\r\n\r\n", $body);

in the smpt/action.php right after the $body is generated
$body = $mailer->dump();

I hope hope this can help in fixing the plugin (I couldn't easily figure out how to fix code on github)

grts

@TVetrovsky
Copy link

TVetrovsky commented May 17, 2018

The suggested fixes did not worked for me.
Configuration:
IIS, PHP 7.2.5, DokuWiki 2018-04-22a "Greebo", SMTP Plugin 2017-08-03, Exchange mail server

Previous fix mentioned by @Netand1 worked for plain text emails but not for HTML emails. There are likely more issues with new line encoding. My fix was:
/site/lib/plugins/smtp/classes/message.php - toString function:

public function toString() {
        // we need to remove the BCC header here
        $body = str_replace("\r\n", "\n", $this->body); // added line
        $lines = explode("\n", $body); // changed line
        $count = count($lines);
        for($i=0; $i<$count; $i++) {
            if(trim($lines[$i]) === '') break; // end of headers, we're done
            if(substr($lines[$i],0, 4) == 'Bcc:') {
                unset($lines[$i]); // we found the Bcc: header and remove it
                while(substr($lines[++$i],0, 1) === ' ') {
                    unset($lines[$i]); // indented lines are header continuiation
                }
                break; // header removed, we're done
            }
        }
        $body = join("\r\n", $lines); // fix suggested by @Netand1

        return $body . $this->CRLF . $this->CRLF . "." . $this->CRLF;
    }

This fix works both for plaintext and html emails.

@rawIce
Copy link

rawIce commented Oct 25, 2018

Ok UNIX problem ..you need to put : \r in line 88 ( $body = join("\r\n", $lines);) of /site/lib/plugins/smtp/classes/message.php

that thing also worked for me, simply add "\r" in the line specified.

rawIce added a commit to rawIce/dokuwiki-plugin-smtp that referenced this issue Oct 25, 2018
@Schroeffu
Copy link

Had the same issue, your workaround #17 (comment) works for me too.

In my case the file is uppercase (Message.php), so (path_to_dokuwiki_htdocs)/lib/plugins/smtp/classes/Message.php

@NiyaShy
Copy link

NiyaShy commented Oct 1, 2019

Can confirm that adding /r on line 88 of Message.php fixes the empty mail body when using the plugin with Exchange (in our case, Exchange 2019). Works for both plain text and HTML mails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants