PDA

View Full Version : SSL/TLS integration for Google Apps


RedHeron
02-14-2008, 03:58 AM
A module to integrate SSL and TLS would be helpful, but I'm not sure where to look for the actual email calls. Additionally, the IMAP module shouldn't be required for POP access in Apache, should it? How about PHP?

My organization is trying to integrate osTicket with the Google Apps system (which is free for up to 100 email users on each domain). We're also using a single collection box for a variety of support request types, so filtering by the "TO" address would also be very helpful as a feature. However, if I can't find a solution by the time the support cases pick up (we're expecting massive increases within the next 6 weeks), then they're going to move to something else.

If anyone can give me some pointers on integrating SSL and TLS into a PHP mail() function, I would be forever grateful, and I think this would benefit the community greatly.

I'm going to continue researching this, but if anyone has any ideas, I'm open to suggestion.

RedHeron
02-14-2008, 04:14 AM
Found this on php.net:

function authgMail($from, $namefrom, $to, $nameto, $subject, $message)
{

/* your configuration here */

$smtpServer = "tls://smtp.gmail.com"; //does not accept STARTTLS
$port = "465"; // try 587 if this fails
$timeout = "45"; //typical timeout. try 45 for slow servers
$username = "yous@gmail.com"; //your gmail account
$password = "y0u4p@55"; //the pass for your gmail
$localhost = $_SERVER['REMOTE_ADDR']; //requires a real ip
$newLine = "\r\n"; //var just for newlines

/* you shouldn't need to mod anything else */

//connect to the host and port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
echo $errstr." - ".$errno;
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
echo $output;
return $output;
}
else
{
$logArray['connection'] = "Connected to: $smtpResponse";
echo "connection accepted<br>".$smtpResponse."<p />Continuing<p />";
}

//you have to say HELO again after TLS is started
fputs($smtpConnect, "HELO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse2'] = "$smtpResponse";

//request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";

//send the username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";

//send the password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";

//email from
fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";

//email to
fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";

//the email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data1response'] = "$smtpResponse";

//construct headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

//observe the . after the newline, it signals the end of message
fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data2response'] = "$smtpResponse";

// say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is a success
return($logArray);
}

This should allow configuration using GMail's SMTP sending mechanism, probably with some slight modifications to integrate better into osTicket.

And now for the retrieve... :)

RedHeron
02-14-2008, 04:30 AM
This file appears to have a lot better functionality with Gmail, and includes what looks to be some retrieving functions. I found it on SourceForge, and it's on an OS license that might be compatible with osTicket.

libgmailer is considered beta, which means it might need some development before integrating into osTicket.

phartes
04-27-2010, 08:46 AM
Conflict

Google Apps does not work for me with IMAP + SMTP. Always try to POP + SMTP

pop.gmail.com
995
yes SSL

ssl://smtp.gmail.com
465
Authentication yes