SSL support - GMail

Artanicus@mythm... - November 28, 2005 - 11:55
Project:SMTP Authentication Support
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:critical
Assigned:LukeLast
Status:closed
Description

The amount of non-SSL smtp servers is shrinking fast, and I for one don't have access to any non-SSL smtp servers thus making my life very much impossible with the poor SSL support of the php mailer and related systems.

Maybe you could save the day and implement support for ssl smtp connections?

#1

LukeLast - November 30, 2005 - 18:09

That sounds cool to me, do you know of any resources to start from?

#2

LukeLast - February 3, 2006 - 21:52
Status:active» closed

I would not be able to do this myself so unless someone can get the ball rolling I'll close the issue.

#3

EmanueleQuinto - October 25, 2006 - 16:43
Title:SSL support» SSL support - GMail
Version:5.x-1.x-dev» 4.7.x-1.x-dev
Status:closed» needs review

Not only the amount of non-SSL smtp servers is shrinking fast, but GMail is asking SSL authentication (on port 465 currently) as stated in Configuring other mail clients.

So if someone is using Google Apps for Your Domain and need to use SMTP there is a possible solution.

First of all you have to check if ssl is enabled in your php configuration (look on php.ini or run phpinfo).

Then use attached patch. What it does?

Following a suggestion on phpmailer forum all that we need it's adding a protocol specification on fsockopen $host parameter. Instead of smtp.gmail.com we need to open ssl://smtp.gmail.com

So basically the patch change on SMTP function Connect($host,$port=0,$tval=30)

<?php
       
#connect to the smtp server
       
$this->smtp_conn = fsockopen($host,    # the host of the server
                                    
$port,    # the port to use
                                    
$errno,   # error number if any
                                    
$errstr# error message if any
                                    
$tval);   # give up after ? secs
?>

to

<?php
       
if($this->Protocol) $host = $this->Protocol."://".$host;

       
#connect to the smtp server
       
$this->smtp_conn = fsockopen($host,    # the host of the server
                                    
$port,    # the port to use
                                    
$errno,   # error number if any
                                    
$errstr# error message if any
                                    
$tval);   # give up after ? secs
?>

Other small changes add parameter management (editing on drupal, adding on class definitions etc.).

Seems to work on drupal 4.7 (if someone is interested there is also a 4.6 patch).

AttachmentSize
smtp47.patch 659 bytes

#4

danbh - October 28, 2006 - 13:01
Status:needs review» needs work

I got this error
warning: fgets() [function.fgets]: SSL: fatal protocol error in /var/www/drupal.hollocher.is-a-geek.com/modules/smtp/smtp.module on line 2775.

and the email did not send

#5

danbh - October 28, 2006 - 13:15
Status:needs work» needs review

I'm sorry, the email did, in fact, send! I do get that warning, but the emails are being sent. Thanks.

#6

EmanueleQuinto - October 28, 2006 - 15:41

On the forum post there is another step that I didn't include in the patch:

3. change to fgets() to @fgets() to surpass the ssl error

Anyway mail is sent.

I googled around to find another solution but I failed :-(

#7

danbh - October 29, 2006 - 16:16

@ doesn't work.
I saw an error report for drupal somewhere mentioning that behavior in a different context. Maybe its a drupal bug.

Regardless, it looks like I will have to live with the error, which is fine.

Thanks!

#8

nrasmus - October 30, 2006 - 17:29

This looks very promising--I do have a question though--if your php.ini has no mention of ssl, what do I do? Running php 4, do I need to recompile that?

#9

nrasmus - November 7, 2006 - 21:44

Just wanted to report something here--it took me almost 2 weeks (of not constant) effort to figure this out:

Depending on where you look, google tells you to use smtp on port 465 or on 587. Turns out that 465 is ssl (not sure what version), and 587 is TLS. FYI--if you have a stable version of php4 or php5, you probably will not get this to work with TLS of 587. With 465, the error danbh reports does show up in your log, but the mails get sent. I didn't dig far enough--but this has something to do with how php can use STARTTLS.

#10

LukeLast - January 17, 2007 - 05:32
Version:4.7.x-1.x-dev» 5.x-1.x-dev
Assigned to:Anonymous» LukeLast
Status:needs review» fixed

Thanks for all the great information.

HEAD has been updated to support SSL. It was working for me with gmail.

#11

Anonymous - January 31, 2007 - 05:46
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.