backdrop / backdrop-issues

Issue tracker for Backdrop core.
145 stars 40 forks source link

SMTP / PHPMailer module in core #3199

Open opi opened 6 years ago

opi commented 6 years ago

Following this discussion on Gitter :

@herbdool We should have an easy way to configure email for sending HTML and via SMTP. Should be much easier than the Drupal 7 setup with Mailsystem

@opi I use https://github.com/makinacorpus/drupal-netsmtp for basic SMTP support in D7. No UI. btw smtp support is good not only for HTML mails, but also to plug backdrop with services like mailjet, mailchimp... would a core support be an improvment for the 80%?

@quicksketch I believe SMTP support is a requirement for all systems that send email (including Backdrop) these days. Sending email is just so hard. It rarely works (getting into actual inboxes) without an external service. So in my opinion, yes I think it's a core candidate.

Describe your issue or idea

Administration interface should provide an easy way to configure an external SMTP server to send every email from Backdrop.

herbdool commented 6 years ago

We'll need to make sure people can still use third party API for sending via SMTP. Sometimes it can just be part of the same UI but I saw this https://www.drupal.org/project/postmark required an alternative to SMTP module.

herbdool commented 6 years ago

We also need to think about how to bake in HTML-enabled emails. Include MimeMail, or https://www.drupal.org/project/swiftmailer or use PHP Mailer for that?

oadaeh commented 6 years ago

The Postmark module uses the Postmark service. It would be like using the Mandrill module, SendGrid Integration module, or other similar modules in that they require and only work with their respective services.

I have more experience with the PHPMailer library and the SMTP module and PHPMailer module, since they have been around much longer. When I last looked at the Swift Mailer module, it was quite limited in what it provided. It's possible that has changed over the years.

Also, note that the version of the PHPMailer library that is included in the SMTP module (both for Backdrop and Drupal) is several years old and should not be used.

Regarding HTML emails, neither the Swift Mailer nor PHPMailer libraries provide for creating HTML messages, they only format the structure of the email so that HTML messages are possible. You would still need something else to create a correctly formatted HTML message body. Now, it seems as though the Swift Mailer module includes some facility for making that happen, which is either new since I last looked at it or didn't work then, but that was quite some time ago. To include HTML message bodies with the PHPMailer library (using either of the modules), you will need to have the Mime Mail module. Those work quite well together.

opi commented 6 years ago

We'll need to make sure people can still use third party API for sending via SMTP.

Using a third party API is different from using a third party SMTP. In both case, one need to define a different system.mail.default-system ;

In my understanding, this issue is to provide another mail system in core (beside DefaultMailSystem) to handle SMTP servers. Am I right ?

Graham-72 commented 6 years ago

I presume this must mean that rather than send email from a Backdrop site, via PHP mail to the local SMTP server (in my case Sendmail running on localhost), one could send to an external mail service's SMTP server, presumably bypassing PHP mail.

The difficulty with using one's local SMTP server is that there is a signicant risk that something will go wrong and perhaps, through no fault of your own, your SMTP server gets on a blacklist. Or some receiving server is badly configured and is declining to accept perfectly legitimate email. I use Views-Send to send out to a fairly limited mailing list, using Mimemail so that HTML email can be suitably formatted, and over the years have experienced occasional difficulties with other 'small player' receiving servers.

So yes, it would be good to be able to identify an alternative and 99.9% reliable SMTP service where someone else takes responsibility for keeping off blacklists.

Graham-72 commented 6 years ago

Is a Backdrop Contrib Module equivalent of something like this what we need? https://en-gb.wordpress.org/plugins/wp-mail-smtp/

jlfranklin commented 6 years ago

Is a Backdrop Contrib Module equivalent of something like this what we need?

We already have it.

Graham-72 commented 6 years ago

That is good to know, thank you.

herbdool commented 6 years ago

@opi I think we should rename this issue. It's not just about SMTP, but about getting SMTP to play nicely with HTML formatting (for example, what MimeMail does). I think parts of the Mailsystem module should go into core, particularly the 3.x branch.

jlfranklin commented 6 years ago

It's not just about SMTP, but about getting SMTP to play nicely with HTML formatting (for example, what MimeMail does).

SMTP is mail transport. SMTP doesn't care if it's plain text, HTML, has a dozen MIME parts for attachments, or international characters. You hand it a fully-formed email (headers and body), tell it the envelope To: and From: (need not be the same as the real To/From), and it sends it. It may add an X-Mailer: header or X-ShamelessPlug: Powered by Backdrop. It may Base64 encode the body to adhere to mail transport standards, but even this is better handled by a higher layer. Anything else is outside the scope of SMTP.

MIMEMail is packaging. Given a number of parts with names/IDs and types, MIMEMail creates the internal structure of the mail. It does not care if it there is an HTML portion, or if that HTML is XHTML 4.03 or HTML5. It may throw a warning if you hand it JSON and tell it "image/gif", but that shouldn't stop it from building the body. Even converting an HTML part to a plain text alternative should be done at a higher level. Should it be stripped down plain text or Rich Text? How about a PDF alternative?

Formatting HTML mail is composition, not transport, nor packaging. An HTML email doesn't care if it is being sent to the local mail daemon via mail(), via SMTP to your in-office mail server, or to a UUNET gateway destined for the last remaining FidoNet BBS. Nor does it care how it's being packaged. There could be an intermediate layer that does additional processing, like Emogrifier converting CSS files to inline, or maybe stripping out large attachments to send via a file sharing service.

HTML != MIME != SMTP. Keep them separate.

herbdool commented 6 years ago

@jlfranklin thank you for the overview. I'm aware of all this. We're talking in the context of how Drupal and Backdrop deal with this and the contrib modules. So it's a matter of getting some improvements into core with existing solutions.

herbdool commented 6 years ago

To help keep my proposal focused, I've added it here: https://github.com/backdrop/backdrop-issues/issues/3218