ProtonMail / proton-bridge

Proton Mail Bridge application
GNU General Public License v3.0
1.14k stars 152 forks source link

Cannot use protonbridge with Nextcloud #428

Open qdii opened 11 months ago

qdii commented 11 months ago

Nextcloud is a famous open-source file management application. It allows to configure a SMTP server to send email to users. However this feature does not seem to work with proton-bridge.

Expected Behavior

An email is sent when Send Test Email is clicked.

Current Behavior

An error message appears in proton bridge logs.

Possible Solution

Steps to Reproduce

  1. Configure Nextcloud using proton-bridge as a SMTP server
  2. Send a test email
  3. Check proto bridge logs
[Sep 29 20:24:20.299] Send mail failed.                             error="failed to parse message: failed to collect attachments: mime: invalid media parameter" pkg=smtp

Version Information

Nextcloud 27.1.1 Proton Bridge 3.4.2

MrIngelborn commented 11 months ago

I have a similar issue. Had it working before on my old Nextcloud server. But now after setting up a new server I can't send any test emails.

ERRO[Oct  1 19:35:06.128] handler error: read tcp 127.0.0.1:1025->127.0.0.1:47632: read: connection reset by peer  pkg=SMTP

Setup:

OpenSUSE Tumbleweed LXC in Proxmox Nextcloud 27.1.1 Proton Bridge 3.4.2

qdii commented 11 months ago

@MrIngelborn I don't think these are the same issues. In my case, the error is "failed to parse message: failed to collect attachments: mime: invalid media parameter", which seems to be a bug in the way Proton Bridge parses the request.

In your case, the error is "read: connection reset by peer", which indicates that the TCP connection was abruptly terminated.

I'd suggest to open a different bug to investigate this.

hluengas commented 11 months ago

I have a similar issue. Had it working before on my old Nextcloud server. But now after setting up a new server I can't send any test emails.

ERRO[Oct  1 19:35:06.128] handler error: read tcp 127.0.0.1:1025->127.0.0.1:47632: read: connection reset by peer  pkg=SMTP

Setup:

OpenSUSE Tumbleweed LXC in Proxmox Nextcloud 27.1.1 Proton Bridge 3.4.2

I am also seeing the same error:

handler error: read tcp 127.0.0.1:1025->127.0.0.1:50568: read: connection reset by peer  pkg=SMTP

Fedora 39 / Nextcloud 27.1.1 / Proton Bridge 3.4.2 & 3.5.1 Have not been able to find the cause yet.

hluengas commented 11 months ago

I did some more testing with earlier versions of proton and nextcloud.

This issue was caused by nextcloud v26 combining the encryption and authentication configuration into one field.

Before v26 you could select Encryption: None but still put in credentials.

Now there is no None option only None/STARTLS. So when this option is selected and credentials are entered it expects to use STARTLS and then closes the connection when proton gives it a self-signed cert.

The solution will probably be to configure nextcloud to accept self signed certs. Instructions for this configuration are here.

hluengas commented 11 months ago

After more testing I have confirmed that the change to the way Nextcloud handles STARTLS is indeed the cause of the problem.

On Proton 3.5.1 and Nextcloud 27.1.1, this problem will go away if you add the following to your Nextcloud config at: config/email.config.php

<?php

$CONFIG = [
    "mail_smtpstreamoptions" => array(
        'ssl' => array(
            'allow_self_signed' => true,
            'verify_peer' => false,
            'verify_peer_name' => false
        )
    )
];

You can also export Proton TLS cert, but that is more involved... and I'm not overly concerned about secure communication between my Proton Bridge container and my Nextcloud container.

qdii commented 10 months ago

@hluengas

I configured Nextcloud with this already: the fact that Protonmail is rejecting the content of the request shows that Nextcloud is accepting the certificate and sending a payload, so it's not the issue (in my case).

LBeernaertProton commented 10 months ago

@qdii can you post the Content-Type of the message you are trying to send? We have a known issue at the moment where if the filename or name attribute is not surrounded by quotes, it's considered invalid.

LBeernaertProton commented 10 months ago

For anyone else in the thread errors such as handler error: read ... can be safely ignored. This is just the IMAP client terminating the connection before we are unable to send them all the responses.

MrIngelborn commented 10 months ago

After more testing I have confirmed that the change to the way Nextcloud handles STARTLS is indeed the cause of the problem.

On Proton 3.5.1 and Nextcloud 27.1.1, this problem will go away if you add the following to your Nextcloud config at: config/email.config.php

<?php

$CONFIG = [
    "mail_smtpstreamoptions" => array(
        'ssl' => array(
            'allow_self_signed' => true,
            'verify_peer' => false,
            'verify_peer_name' => false
        )
    )
];

You can also export Proton TLS cert, but that is more involved... and I'm not overly concerned about secure communication between my Proton Bridge container and my Nextcloud container.

Thanks! That did solve my issue!

qdii commented 10 months ago

@qdii can you post the Content-Type of the message you are trying to send? We have a known issue at the moment where if the filename or name attribute is not surrounded by quotes, it's considered invalid.

OK, I'll try to dump the communication so we can debug (by the way, having an option to do that on ProtonBridge CLI would be amazing).

It looks like Nextcloud's code to send a test email is here

LBeernaertProton commented 10 months ago

If possible, could you post the sent email headers that next cloud sends to a working account?

hluengas commented 10 months ago

Here are the headers from a nextcloud test email:

X-Pm-Content-Encryption: end-to-end
X-Pm-Origin: internal
Subject: Email setting test
To: nextcloud-admin <redacted>
From: Nextcloud <redacted>
Message-Id: <018e7d6e8b48c40dee06700de0019607@redacted>
Date: Mon, 09 Oct 2023 00:59:28 +0000
Mime-Version: 1.0
Content-Type: text/html
X-Pm-Recipient-Authentication: redacted=pgp-pm
X-Pm-Recipient-Encryption: redacted=pgp-pm-pinned
X-Original-To: redacted
Return-Path: <redacted>
Delivered-To: redacted 
Received: from mail.protonmail.ch by mail.protonmail.ch; Mon, 09 Oct 2023 00:59:28 +0000
LBeernaertProton commented 10 months ago

Does the message have any other parts and/or attachments? The error in the root post refers to an attachments, but I don't see anything in those headers that would indicate there is an attachment.

hluengas commented 10 months ago

no attachments... here's the HTML body:

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"
    style="-webkit-font-smoothing:antialiased;background:#fff!important">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <style type="text/css">
        @media only screen {
            html {
                min-height: 100%;
                background: #fff
            }
        }

        @media only screen and (max-width:610px) {
            table.body img {
                width: auto;
                height: auto
            }

            table.body center {
                min-width: 0 !important
            }

            table.body .container {
                width: 95% !important
            }

            table.body .columns {
                height: auto !important;
                -moz-box-sizing: border-box;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                padding-left: 30px !important;
                padding-right: 30px !important
            }

            th.small-12 {
                display: inline-block !important;
                width: 100% !important
            }

            table.menu {
                width: 100% !important
            }

            table.menu td,
            table.menu th {
                width: auto !important;
                display: inline-block !important
            }

            table.menu.vertical td,
            table.menu.vertical th {
                display: block !important
            }

            table.menu[align=center] {
                width: auto !important
            }
        }
    </style>
</head>

<body
    style="-moz-box-sizing:border-box;-ms-text-size-adjust:100%;-webkit-box-sizing:border-box;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;margin:0;background:#fff!important;box-sizing:border-box;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;min-width:100%;padding:0;text-align:left;width:100%!important">
    <span class="preheader"
        style="color:#F5F5F5;display:none!important;font-size:1px;line-height:1px;max-height:0;max-width:0;mso-hide:all!important;opacity:0;overflow:hidden;visibility:hidden">
    </span>
    <table class="body"
        style="-webkit-font-smoothing:antialiased;margin:0;background:#fff;border-collapse:collapse;border-spacing:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;width:100%">
        <tbody>
            <tr style="padding:0;text-align:left;vertical-align:top">
                <td class="center" align="center" valign="top"
                    style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
                    <center data-parsed="" style="min-width:580px;width:100%">
                        <table align="center" class="wrapper header float-center"
                            style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
                            <tbody>
                                <tr style="padding:0;text-align:left;vertical-align:top">
                                    <td class="wrapper-inner"
                                        style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word">
                                        <table align="center" class="container"
                                            style="Margin:0 auto;background:0 0;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:150px">
                                            <tbody>
                                                <tr style="padding:0;text-align:left;vertical-align:top">
                                                    <td
                                                        style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
                                                        <center data-parsed=""
                                                            style="background-color:#0082c9;min-width:175px;max-height:175px; padding:35px 0px;border-radius:200px">
                                                            <img class="logo float-center"
                                                                src="http://redacted.example.com/core/img/logo/logo.png?v=0"
                                                                alt="Nextcloud" align="center"
                                                                style="-ms-interpolation-mode:bicubic;clear:both;display:block;float:none;margin:0 auto;outline:0;text-align:center;text-decoration:none;max-height:105px;max-width:105px;width:auto;height:auto" />
                                                        </center>
                                                        <table class="row collapse"
                                                            style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
                                                            <tbody>
                                                                <tr
                                                                    style="padding:0;text-align:left;vertical-align:top">

                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <table class="spacer float-center"
                            style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
                            <tbody>
                                <tr style="padding:0;text-align:left;vertical-align:top">
                                    <td height="40px"
                                        style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:80px;font-weight:400;hyphens:auto;line-height:80px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <table align="center" class="container main-heading float-center"
                            style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px">
                            <tbody>
                                <tr style="padding:0;text-align:left;vertical-align:top">
                                    <td
                                        style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
                                        <h1 class="text-center"
                                            style="Margin:0;Margin-bottom:10px;color:inherit;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:center;word-wrap:normal">
                                            Well done, nextcloud-admin!</h1>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <table class="spacer float-center"
                            style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
                            <tbody>
                                <tr style="padding:0;text-align:left;vertical-align:top">
                                    <td height="36px"
                                        style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:40px;font-weight:400;hyphens:auto;line-height:36px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <table align="center" class="wrapper content float-center"
                            style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
                            <tbody>
                                <tr style="padding:0;text-align:left;vertical-align:top">
                                    <td class="wrapper-inner"
                                        style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
                                        <table align="center" class="container"
                                            style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
                                            <tbody>
                                                <tr style="padding:0;text-align:left;vertical-align:top">
                                                    <td
                                                        style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
                                                        <table class="row description"
                                                            style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
                                                            <tbody>
                                                                <tr
                                                                    style="padding:0;text-align:left;vertical-align:top">
                                                                    <th class="small-12 large-12 columns first last"
                                                                        style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
                                                                        <table
                                                                            style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
                                                                            <tbody>
                                                                                <tr
                                                                                    style="padding:0;text-align:left;vertical-align:top">
                                                                                    <th
                                                                                        style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
                                                                                        <p
                                                                                            style="Margin:0;Margin-bottom:10px;color:#777;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center">
                                                                                            If you received this
                                                                                            email, the email
                                                                                            configuration seems to
                                                                                            be correct.</p>
                                                                                    </th>
                                                                                    <th class="expander"
                                                                                        style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0">
                                                                                    </th>
                                                                                </tr>
                                                                            </tbody>
                                                                        </table>
                                                                    </th>
                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <table class="spacer float-center"
                            style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
                            <tbody>
                                <tr style="padding:0;text-align:left;vertical-align:top">
                                    <td height="60px"
                                        style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <table align="center" class="wrapper footer float-center"
                            style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
                            <tbody>
                                <tr style="padding:0;text-align:left;vertical-align:top">
                                    <td class="wrapper-inner"
                                        style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
                                        <center data-parsed="" style="min-width:580px;width:100%">
                                            <table class="spacer float-center"
                                                style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
                                                <tbody>
                                                    <tr style="padding:0;text-align:left;vertical-align:top">
                                                        <td height="15px"
                                                            style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:15px;font-weight:400;hyphens:auto;line-height:15px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                            <p class="text-center float-center" align="center"
                                                style="Margin:0;Margin-bottom:10px;color:#C8C8C8;font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&#39;Helvetica Neue&#39;,Arial,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">
                                                Nextcloud - a safe home for all your data<br />This is an
                                                automatically sent email, please do not reply.</p>
                                        </center>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </center>
                </td>
            </tr>
        </tbody>
    </table>
    <!-- prevent Gmail on iOS font size manipulation -->
    <div style="display:none;white-space:nowrap;font:15px courier;line-height:0"> </div>

</body>

</html>