Hi,

For a few times I've had to deal with clients that have badly configured SMTP servers, and I don't have any power over it, so I have to use the server/accounts that they provide to me.

The most of the times, the main problem is servers that have self-signed certificates, and this module doesn't have any option to allow it to make connections to those kinds of servers.

I took a look at the module, and I found that it uses fsockopen() ( https://www.php.net/manual/en/function.fsockopen.php ) to create the socket to the SMTP server ( https://git.drupalcode.org/project/smtp/blob/8.x-1.0-beta4/src/PHPMailer... ). So I changed it to use stream_socket_client() ( https://www.php.net/manual/en/function.stream-socket-client.php ) that has the same arguments as the fsockopen(), but has an extra argument that is the $context.

Creating a $context like this, allows us to connect to servers with self signed certificates.

$options = [
    'ssl' => [
        'verify_peer_name' => false,
        'verify_peer'      => false,
        'allow_self_signed' => true,
    ]
];

$context = stream_context_create($options);

So what I've changed, is:

* Added a new checkbox to the module configuration form, called smtp_self_signed. With a warning telling people to enable it only if they know what they are doing;
* Added the same variable to smtp.settings.yml and smtp.schema.yml;
* Added the glue needed to pass the new option from the form to the PHPMailer.php and SMTP.php files;
* Using stream_socket_client() instead of fsockopen() to create the connection;
* When smtp_self_signed is set to True, create a context that allows connections to servers with self-signed certificates;

The attached patch is based on the latest branch "8.x-1.x" on git. This is my first time submitting a patch to add a new feature to a Drupal module, so be gentle ;-)

Regards,
Pedro de Oliveira @ Javali

Issue fork smtp-3069577

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

falsovsky created an issue. See original summary.

falsovsky’s picture

Status: Active » Needs review
mario.martins’s picture

Status: Needs review » Reviewed & tested by the community

It seems a nice solution.

gueguerreiro’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -smtp, -certificate
Related issues: +#2711559: Set phpMailer as a external library using composer (and update it to 6.0), +#2295773: D7.x: Update PHPMailer to v6.0

Thank you for your work.

I'm removing the issue tags. As per the description at the bottom of the field:

Do NOT use tags for adding random keywords or duplicating any other fields.

Having a working patch is great, and someone with the same problem might stumble upon this issue and apply the patch directly in a pinch. I don't think it's ready for a commit and release, however.

Editing PHPMailer.php directly seems ill advised at best. Ideally, this module should have required it via composer, and not added the files directly in the first place.

But if that's not a solution, surely just updating the PHPMailer version to the most recent version would make the most sense? The current version (6.1.1) already uses stream_socket_client() and accepts an array of context options on the options parameter as a last argument to the connect() function: https://github.com/PHPMailer/PHPMailer/blob/master/src/SMTP.php#L299. But since this is a major version change I'm not sure if any existing code would break, however.

Either way, this issue seems like another reason why this module should be using composer for its packaging dependencies...

This solution would enter in direct conflict with either #2711559 or #2295773 when (or if) they land.

falsovsky’s picture

Hi @gueguerreiro,

I also found very weird that the module includes a hacked and very old fork of PHPMailer, but I tried to work with it because of a client with a badly configured email server.

I'm of your opinion that a composer version of PHPMailer should be used.

Lets hope if #2711559 or #2295773 get merged.

Thanks for reviewing.

rivimey’s picture

Status: Needs work » Postponed

mkoul made their first commit to this issue’s fork.

mkoul’s picture

StatusFileSize
new2.61 KB

Hello there, I updated the patch of @falsovsky to work with the latest version of this module.

agusfernandezg9’s picture

StatusFileSize
new5.81 KB

Following this topic, we needed to add a CA certificate to the SMTP configuration.
We added 2 options to be able to set up your custom CA certificate file, for this, we've created 2 extra fields.
1- Self-signed certificate, it's a boolean to determine if you need a custom certificate or not.
2- Certificate File, it's the certificate file itself.

agusfernandezg9’s picture

StatusFileSize
new5.84 KB

There was a missing field on the submit method, so I've re-added so now the value it's been stored.

ramonma1989’s picture

I used #10 with smtp 8.x-1.2, it worked for me, thanks.

japerry’s picture

Status: Postponed » Needs work

Moving back to needs work. I think the feature, very unfortunately, should exist... but the patch needs some work, specifically around managing the configuration.

tomsaw’s picture

#10 works for me with a bad uggly singed certificate using (latest) Drupal 10.1.1
Thanks to everyone involved!

andywits’s picture

StatusFileSize
new5.78 KB

In my case, #10 patch was incorrectly applied on version 8.x-1.4.
I modified it a bit and posted it under number #14.
Maybe it will be useful to someone.

bluegeek9’s picture

Assigned: Unassigned » bluegeek9
Status: Needs work » Active
bluegeek9’s picture

Assigned: bluegeek9 » Unassigned
Status: Active » Needs review

There is a merge request that addresses this. Please review.
#3230777: Mutual TLS authentication support

bluegeek9’s picture

This feature was added in #3230777: Mutual TLS authentication support. I am setting the status to fixed to grant everyone credit for their contribution.

//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:
  • Triage issues and adding more context to existing issues.
  • Flagging SMTP as a favorite on the project page to help others discover it and show your support.
bluegeek9’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

hablat’s picture

Is there a patch we can use that works for the current stable release 8x-1.4. The MR currently isn't applying