diff --git a/admin/settings/server.php b/admin/settings/server.php
index f56484b..1fd1044 100644
--- a/admin/settings/server.php
+++ b/admin/settings/server.php
@@ -21,6 +21,8 @@ $ADMIN->add('server', $temp, 0);
 // "email" settingpage
 $temp = new admin_settingpage('mail', get_string('mail','admin'));
 $temp->add(new admin_setting_configtext('smtphosts', get_string('smtphosts', 'admin'), get_string('configsmtphosts', 'admin'), '', PARAM_RAW));
+$options = array('' => get_string('none', 'admin'), 'ssl' => 'SSL');
+$temp->add(new admin_setting_configselect('smtpsecure', get_string('smtpsecure', 'admin'), get_string('configsmtpsecure', 'admin'), '', $options));
 $temp->add(new admin_setting_configtext('smtpuser', get_string('smtpuser', 'admin'), get_string('configsmtpuser', 'admin'), '', PARAM_NOTAGS));
 $temp->add(new admin_setting_configpasswordunmask('smtppass', get_string('smtppass', 'admin'), get_string('configsmtpuser', 'admin'), ''));
 $temp->add(new admin_setting_configtext('smtpmaxbulk', get_string('smtpmaxbulk', 'admin'), get_string('configsmtpmaxbulk', 'admin'), 1, PARAM_INT));
diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php
index 6f88a99..3b303a7 100644
--- a/lang/en_utf8/admin.php
+++ b/lang/en_utf8/admin.php
@@ -244,6 +244,7 @@ $string['configslasharguments'] = 'Files (images, uploads etc) are provided via
 $string['configsmartpix'] = 'With this on, icons are served through a PHP script that searches the current theme, then all parent themes, then the Moodle /pix folder. This reduces the need to duplicate image files within themes, but has a slight performance cost.';
 $string['configsmtpmaxbulk'] = 'Maximum number of messages sent per SMTP session. Grouping messages may speed up the sending of emails. Values lower than 2 force creation of new SMTP session for each email.';
 $string['configsmtphosts'] = 'Give the full name of one or more local SMTP servers that Moodle should use to send mail (eg \'mail.a.com\' or \'mail.a.com;mail.b.com\'). To specify a non-default port (i.e other than port 25), you can use the [server]:[port] syntax (eg \'mail.a.com:587\'. If you leave it blank, Moodle will use the PHP default method of sending mail.';
+$string['configsmtpsecure'] = 'If smtp server requires secure connection, specify the correct protocol type.';
 $string['configsmtpuser'] = 'If you have specified an SMTP server above, and the server requires authentication, then enter the username and password here.';
 $string['configstartwday'] = 'Start of Week';
 $string['configstatscatdepth'] = 'Statistics code uses simplified course enrolment logic, overrides are ignored and there is a maximum number of verified parent course categories. Number 0 means detect only direct role assignments on site and course level, 1 means detect also role assignments in parent category of course, etc. Higher numbers result in much higher database server load during stats processing.';
@@ -555,6 +556,7 @@ $string['nochanges'] = 'No changes';
 $string['nodefaultuserrolelists'] = 'Don\'t return all default role users';
 $string['nolangupdateneeded'] = 'All your language packs are up to date, no update is needed';
 $string['nomissingstrings'] = 'No missing strings';
+$string['none'] = 'None';
 $string['nonewsettings'] = 'No new settings were added during this upgrade.';
 $string['nonexistentbookmark'] = 'The bookmark you requested does not exist.';
 $string['nonmetacoursesyncroleids'] = 'Roles that are not synchronised to metacourses';
@@ -714,6 +716,7 @@ $string['sitesectionhelp'] = 'If selected, a topic section will be displayed on
 $string['slasharguments'] = 'Use slash arguments';
 $string['smartpix'] ='Smart pix search';
 $string['smtphosts'] = 'SMTP hosts';
+$string['smtpsecure'] = 'SMTP security';
 $string['smtpmaxbulk'] = 'SMTP session limit';
 $string['smtppass'] = 'SMTP password';
 $string['smtpuser'] = 'SMTP username';
diff --git a/lib/phpmailer/class.phpmailer.php b/lib/phpmailer/class.phpmailer.php
index 53d3668..efadcd1 100644
--- a/lib/phpmailer/class.phpmailer.php
+++ b/lib/phpmailer/class.phpmailer.php
@@ -538,6 +538,7 @@ class PHPMailer
      * @return bool
      */
     function SmtpConnect() {
+        global $CFG;
         if($this->smtp == NULL) { $this->smtp = new SMTP(); }
 
         $this->smtp->do_debug = $this->SMTPDebug;
@@ -548,14 +549,26 @@ class PHPMailer
         // Retry while there is no connection
         while($index < count($hosts) && $connection == false)
         {
-            if(strstr($hosts[$index], ":"))
-                list($host, $port) = explode(":", $hosts[$index]);
+            $hostinfo = array();
+            if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
+                $host = $hostinfo[1];
+                $port = $hostinfo[2];
+            }
             else
             {
                 $host = $hosts[$index];
                 $port = $this->Port;
             }
 
+            // Add SSL prefix to host if required
+            if (isset($CFG->smtpsecure)) {
+                if ($CFG->smtpsecure == "ssl") {
+                    if (strtolower(substr($host,0,6)) != "ssl://") {
+                        $host = "ssl://".$host;
+                    }
+                }
+            }
+
             if($this->smtp->Connect($host, $port, $this->Timeout))
             {
                 if ($this->Helo != '')
