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
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | 8.x-1.x-allow_self_signed-14.patch | 5.78 KB | andywits |
| #10 | 8.x-1.x-allow_self_signed-10.patch | 5.84 KB | agusfernandezg9 |
| #9 | 8.x-1.x-allow_self_signed-9.patch | 5.81 KB | agusfernandezg9 |
| #8 | 8.x-1.x-allow_self_signed-8.patch | 2.61 KB | mkoul |
Issue fork smtp-3069577
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
Comment #2
falsovsky commentedComment #3
mario.martins commentedIt seems a nice solution.
Comment #4
gueguerreiroThank you for your work.
I'm removing the issue tags. As per the description at the bottom of the field:
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 theoptionsparameter as a last argument to theconnect()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.
Comment #5
falsovsky commentedHi @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.
Comment #6
rivimeyComment #8
mkoul commentedHello there, I updated the patch of @falsovsky to work with the latest version of this module.
Comment #9
agusfernandezg9 commentedFollowing 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.
Comment #10
agusfernandezg9 commentedThere was a missing field on the submit method, so I've re-added so now the value it's been stored.
Comment #11
ramonma1989I used #10 with smtp 8.x-1.2, it worked for me, thanks.
Comment #12
japerryMoving back to needs work. I think the feature, very unfortunately, should exist... but the patch needs some work, specifically around managing the configuration.
Comment #13
tomsaw commented#10 works for me with a bad uggly singed certificate using (latest) Drupal 10.1.1
Thanks to everyone involved!
Comment #14
andywits commentedIn 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.
Comment #15
bluegeek9 commentedComment #16
bluegeek9 commentedThere is a merge request that addresses this. Please review.
#3230777: Mutual TLS authentication support
Comment #17
bluegeek9 commentedThis feature was added in #3230777: Mutual TLS authentication support. I am setting the status to fixed to grant everyone credit for their contribution.
Comment #18
bluegeek9 commentedComment #21
hablat commentedIs there a patch we can use that works for the current stable release 8x-1.4. The MR currently isn't applying