Thursday, October 25, 2012

Re: Sending mail through Gmail with CakeEmail (again)?

I am using Gmail SMTP on local host and web server as well here is my code.

In email.php inside app/Config

public $gmail = array(
        'transport' => 'Smtp',
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'timeout' => 30000,
        'username' => 'youremail@gmail.com',
        'password' => 'yourpassword',
        'client' => null,
        'log' => true
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    );
 

And in any controller for sending emails-

$fromConfig = 'Sender Email';
$fromNameConfig = 'Sender Email';
$emailObj = new CakeEmail();
$emailObj->from(array( $fromConfig => $fromNameConfig));
$emailObj->sender(array( $fromConfig => $fromNameConfig));
$emailObj->subject('Mail Subject');
$body='Mail Body';
// we are using gmail config for sending mails through Gmail Smtp
$emailObj->config('gmail');
$result = $emailObj->send($body);


On Wed, Oct 24, 2012 at 11:12 AM, Vanja Dizdarević <lex.non.scripta@gmail.com> wrote:
Sorry for not bumping old topics, but has anyone managed to send an email with CakeEmail and stmp.gmail.com?

My settings:
class EmailConfig {
public $gmail = array(
'transport' => 'Smtp',
'from' => array('user@domain.com' => 'Name'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 10,
'username' => 'user@domain.com',
'password' => 'youwishyouknew',
'client' => null,
'log' => true,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
                'emailFormat' => 'html'
);

My Controller code:
function test_email(){
$mail = new CakeEmail('gmail');
                $mail->addTo('user@anotherdomain.com', 'User');
                $mail->from('user@domain.com', 'User');
                $mail->subject('TESTING '.rand(10, 100));
                $mail->template('test', 'default');
                $return = $mail->send();
                debug($return);
                debug($mail);
        die();
}
I keep getting Connection timeouts and Socket errors. Basically, the damn thing won't even connect, auth is never even touched. (neither dev, nor production machine..)

I am using Google Apps on that domain (same domain as the production, not that it should matter...)

I have checked for mod_openssl on the server.
I have double checked the auth info.
I am using Cake 2.2.1

Is there something else I'm missing? Or should I just search for another email library?

Thanks! Cheers!

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 



--
Chetan Varshney
Ektanjali Softwares Pvt Ltd

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: