Apr 27th, 2009, 9:11 PM
This thread describes a way to use FT2 and the Swift Mailer module with SMTP to a Gmail account. It described changes to files in the Swift Mailer module v1.0.0-beta-20090409. It enables FT2 to meet the following Gmail requirements:
1) use a SSL (not TLS) encrypted connection to Gmail SMTP
2) authenticate to your Gmail account
3) use the Swift Mailer batchSend function which defaults to only show the individual's To: address on each email and suppress the others in the list (ignores the CC: and BCC: fields)
4) use the Swift Mailer anti-flood function to limit outbound emails to 100 or less per connection
First go into the Modules section and select Swift Mailer. Update the following values:
Enabled - Yes
SMTP Server - smtp.gmail.com
Port - 465
Requires authentication - Yes
Username - example@gmail.com
Password - your Gmail password
Authentication procedure - LOGIN
Next we need to makes 4 changes to the following file.
formtools/modules/swift_mailer/library.php - change 1 of 4
This change requires (adds) the anti-flood class included with the Swift Mailer modules for later use in the script.
change this:
to this:
formtools/modules/swift_mailer/library.php - change 2 of 4
This change creates a SSL encrypted connection to Gmail. Notice I commented out the previous line. Gmail offers port 465 for SSL and 587 for TLS encrypted connections. I read that Swift Mailer supports SSL, not TLS, but that information may be dated now.
change this:
to this:
formtools/modules/swift_mailer/library.php - change 3 of 4
This change brings the anti-flood code into play so you don't exceed Gmail's 100 emails per connection limit. This setting sends out 90 emails per batch then waits 2 seconds before opening up the next connection if needed.
change this:
to this:
formtools/modules/swift_mailer/library.php - change 4 of 4
This change uses the batchSend() instead of the send() function. Notice I commented out the previous line. This will cause individual emails to be sent with just the recipient's email in the To: field. It will not send the entire email list to each recipient. The CC: and BCC: fields are ignored with batchSend().
change this:
to this:
Finally we need to make 1 change to the following file.
formtools/modules/swift_mailer/php5/ft_library.php - change 1 of 1
This change is not required unless you want to use the test functions. Notice I commented out the previous line again.
change this:
to this:
Hopefully this thread will help others looking to use Gmail as their SMTP server. It will work well for an email list with only 1 address to very long lists. Keep in mind that if you try to use this technique to send spam that Gmail will identify the activity by the higher rate of returns and rejects and lock your account for 24-48 hours. Abuse this at your own risk! YMMV!
Chuck
1) use a SSL (not TLS) encrypted connection to Gmail SMTP
2) authenticate to your Gmail account
3) use the Swift Mailer batchSend function which defaults to only show the individual's To: address on each email and suppress the others in the list (ignores the CC: and BCC: fields)
4) use the Swift Mailer anti-flood function to limit outbound emails to 100 or less per connection
First go into the Modules section and select Swift Mailer. Update the following values:
Enabled - Yes
SMTP Server - smtp.gmail.com
Port - 465
Requires authentication - Yes
Username - example@gmail.com
Password - your Gmail password
Authentication procedure - LOGIN
Next we need to makes 4 changes to the following file.
formtools/modules/swift_mailer/library.php - change 1 of 4
This change requires (adds) the anti-flood class included with the Swift Mailer modules for later use in the script.
change this:
Code:
// include the main files
$current_folder = dirname(__FILE__);
require_once("$current_folder/$php_version_folder/Swift.php");
require_once("$current_folder/$php_version_folder/Swift/Connection/SMTP.php");
$settings = ft_get_module_settings("", "swift_mailer");
Code:
// include the main files
$current_folder = dirname(__FILE__);
require_once("$current_folder/$php_version_folder/Swift.php");
require_once("$current_folder/$php_version_folder/Swift/Connection/SMTP.php");
// gmail anti-flood
require_once("$current_folder/$php_version_folder/Swift/Plugin/AntiFlood.php");
$settings = ft_get_module_settings("", "swift_mailer");
formtools/modules/swift_mailer/library.php - change 2 of 4
This change creates a SSL encrypted connection to Gmail. Notice I commented out the previous line. Gmail offers port 465 for SSL and 587 for TLS encrypted connections. I read that Swift Mailer supports SSL, not TLS, but that information may be dated now.
change this:
Code:
if (empty($port))
$smtp =& new Swift_Connection_SMTP($smtp_server);
else
$smtp =& new Swift_Connection_SMTP($smtp_server, $port);
Code:
if (empty($port))
$smtp =& new Swift_Connection_SMTP($smtp_server);
else
// $smtp =& new Swift_Connection_SMTP($smtp_server, $port);
// gmail secure connection, ENC_SSL for 465 or ENC_TLS for 587
$smtp =& new Swift_Connection_SMTP($smtp_server, $port, Swift_Connection_SMTP::ENC_SSL);
formtools/modules/swift_mailer/library.php - change 3 of 4
This change brings the anti-flood code into play so you don't exceed Gmail's 100 emails per connection limit. This setting sends out 90 emails per batch then waits 2 seconds before opening up the next connection if needed.
change this:
Code:
if ($settings["requires_authentication"] == "yes")
{
$smtp->setUsername($settings["username"]);
$smtp->setPassword($settings["password"]);
}
$swift =& new Swift($smtp);
Code:
if ($settings["requires_authentication"] == "yes")
{
$smtp->setUsername($settings["username"]);
$smtp->setPassword($settings["password"]);
}
$swift =& new Swift($smtp);
//gmail anti-flood
$swift->attachPlugin(new Swift_Plugin_AntiFlood(90, 2), "anti-flood");
formtools/modules/swift_mailer/library.php - change 4 of 4
This change uses the batchSend() instead of the send() function. Notice I commented out the previous line. This will cause individual emails to be sent with just the recipient's email in the To: field. It will not send the entire email list to each recipient. The CC: and BCC: fields are ignored with batchSend().
change this:
Code:
$swift->send($email, $recipients, $from);
return array($success, $message);
}
Code:
// $swift->send($email, $recipients, $from);
// gmail batchSend
$swift->batchSend($email, $recipients, $from);
return array($success, $message);
}
Finally we need to make 1 change to the following file.
formtools/modules/swift_mailer/php5/ft_library.php - change 1 of 1
This change is not required unless you want to use the test functions. Notice I commented out the previous line again.
change this:
Code:
if (empty($port))
$smtp =& new Swift_Connection_SMTP($smtp_server);
else
$smtp =& new Swift_Connection_SMTP($smtp_server, $port);
Code:
if (empty($port))
$smtp =& new Swift_Connection_SMTP($smtp_server);
else
// $smtp =& new Swift_Connection_SMTP($smtp_server, $port);
// gmail added (, Swift_Connection_SMTP::ENC_SSL) port 465 for SSL or 587 for TLS
$smtp =& new Swift_Connection_SMTP($smtp_server, $port, Swift_Connection_SMTP::ENC_SSL);
Hopefully this thread will help others looking to use Gmail as their SMTP server. It will work well for an email list with only 1 address to very long lists. Keep in mind that if you try to use this technique to send spam that Gmail will identify the activity by the higher rate of returns and rejects and lock your account for 24-48 hours. Abuse this at your own risk! YMMV!
Chuck