Asked  1 Year ago    Answers:  5   Viewed   21 times

i'm trying to use the codeigniter email class to write a secure smtp email; either ssl or tls (preferred). in the past, i've successfully used phpmailer with secure auth and tls. i believe it was a secure connection. tls shows up in the email header.

does codeingiters' email class support secure smtp authentication with tls?

note, this is not a gmail question. i'm trying to use it with an ms exchange server. i've confirmed the phpmailer code below functions correctly.

include_once('includes/class.phpmailer.php');
$mail = new phpmailer(true);
$mail->issmtp();
$mail->host = 'www.domain.com';

$mail->smtpauth = true;
$mail->smtpsecure = "tls";
$mail->port     = '25';
$mail->timeout  = '60';

$mail->username = 'user@domain.com';
$mail->password = 'password';

$mail->from     = 'alerts@domain.com';
$mail->fromname = 'alerts';

$mail->subject  = 'test from test email file.';
$mail->ishtml(true);
$mail->msghtml('this is just a test.');

// to
$mail->addaddress('alerts@domain.com', 'research');
$result = $mail->send();

with codeigniter i've already extended the email class (my_email.php). the class is a bit big to post here. but, here's the error i keep getting.

settings:

array(7) { 
["smtp_host"]=> string(26) "tls://www.domain.com" 
["smtp_port"]=> string(2) "25" 
["smtp_user"]=> string(17) "alerts@domain.com" 
["smtp_pass"]=> string(9) "password" 
["smtp_to_email"]=> string(26) "user@domain.com" 
["smtp_from_email"]=> string(26) "user@domain.com" 
["smtp_from_name"]=> string(24) "test from application" 
}

error message:

fsockopen(): ssl operation failed with code 1. openssl error messages: error:1408f10b:ssl routines:func(143):reason(267)

any idea what reason 267 is?

 Answers

4

found a solution on the ci forums.

exchange email class patch http://codeigniter.com/forums/viewthread/158882/

it is initiating tls after smtp server has been connected.

worked for me. jeff

Saturday, May 29, 2021
 
revive
 
1

that's odd, specially since not all the ns are transliterated and not at a specific position.

try calling $this->email->set_crlf( "rn" ); as well. look up the message details in exchange and inspect the content-type and charset / encoding - post the raw thing here so we can inspect it.

i found this in microsoft knowledgebase:

microsoft exchange uses an enhanced character set. the default mime character set for microsoft exchange is iso 8859-1. some gateways do not support the way this character set issues a soft return for line feeds. when this occurs, each line is terminated with an equal sign showing the line break where the gateway's line-length support ends.

Thursday, April 1, 2021
 
1

any developer with access to your code will be able to access your credentials. saving these in a database may make it a little tougher to gain access to the details, but only slightly.

if you are truly concerned about the credentials used, create an account dedicated to your site and do not use a personal account.

Thursday, April 1, 2021
 
3

some have reported having an issue with a config item having single quotes:

$config['crlf'] = 'rn';      //should be "rn"
$config['newline'] = 'rn';   //should be "rn"

i'm pretty certain protocol => mail does not use your provider -- it will send the email directly from your server.

if it's not the single quote issue, it might be an issue with incorrect credentials, firewall or connection requirement (say if your email provider requires tls/ssl).

try connecting to the mail server and send an email with another client (you could use telnet: http://www.wikihow.com/send-email-using-telnet or thunderbird or somesuch) to verify the protocols are correct.

Sunday, August 15, 2021
 
3

the error you get means the smtp server you're talking to doesn't claim to support authentication. if you look at the debug output you'll see that none of the responses to your ehlos contain the necessary declaration for auth. if it did (properly) support authentication, one of the responses would be something like:

250 auth gssapi digest-md5 plain

(at least in reponse to the ehlo after the starttls.) because that response isn't included, smtplib assumes the server won't be able to handle the auth command, and will refuse to send it. if you're certain your smtp server does support the auth command even though it doesn't advertise it, you can sneakily convince smtplib that it supports auth by explicitly adding it to the set of features. you'll need to know which kind of authentication schemes are supported, and then you can do:

smtp.starttls()
smtp.ehlo()
# pretend the smtp server supports some forms of authentication.
smtp.esmtp_features['auth'] = 'login digest-md5 plain'

... but of course making the smtp server behave according to spec would be a better idea :)

Thursday, August 19, 2021
 
Jon
 
Jon
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :