1

I had written following code to send email.

static function sendEmail($email,$data,$type){


    $Email = new CakeEmail();       
    $Email->config('general');
    switch($type){
        case 1:
            $Email->template('confirmation_free', null);
            $Email->subject('Confirmation of registration with XXXXXXXXXXXXX');
            $Email->viewVars(array('Email'=>$data["Email"],'full_name'=>$data['full_name'],'Id'=>$data['Id'],'url'=>$_SERVER['SERVER_NAME'], 'password'=>$data['password']));
            break;
        case 2:
            $Email->template('group-invite', 'default');
            $Email->subject('XXXXXXXX Group Invite - Notification');
            $Email->viewVars(array('Email'=>$data["Email"],'Username'=>$data['Username'],'Id'=>$data['Id'],'url'=>$_SERVER['SERVER_NAME']));
            break;
        case 3:
            $Email->template('forgot_password', null);
            $Email->subject('XXXXXXXX - Forgot Password');
            $Email->viewVars(array('Email'=>$data["Email"],'Key'=>$data['Key'],'url'=>$_SERVER['SERVER_NAME'],'Id'=>$data['id']));
            break;
    }
    $Email->to($email);
    if($Email->send())
        return true;
    else
        return false;
}

with following sendgrid smtp settings.

public $general = array(
    'transport' => 'Smtp',
    'from' => array('XXXXX@XXXXXXX' => 'XXXXXX Administrator'),
    'host' => 'smtp.sendgrid.net',
    'port' => 587,
    'timeout' => 30,
    'username' => 'XXXXXXX',
    'password' => 'XXXXXX',
    'client' => null,
    'log' => false,
    'emailFormat' => 'html'
);

It was working perfectly fine on my local and dev server. But after we installed SSL on the dev server, it started throwing following error "SMTP server did not accept the password "

Please note that I'm using a sendgrid free account. Do I need a paid account to send emails from a server with SSL?

Xylon
  • 461
  • 4
  • 11
  • 20

3 Answers3

0

You need to either use the tls option in your CakeEmail config or prefix the host with ssl:// https://book.cakephp.org/2.0/en/core-utility-libraries/email.html

bwest
  • 9,182
  • 3
  • 28
  • 58
0

Xylon, Please try this.

In Email.php

public $smtp = array(
    'host' => 'ssl://smtp.gmail.com',
            'port' => 465,
            'username'  => 'your email',
            'password'  => 'password',
            'transport' => 'Smtp',
            'log' => true,
            'auth' => true,
            'charset' => 'utf-8',
            'headerCharset' => 'utf-8',
    );
    $Email = new CakeEmail('smtp'); // In Controller where you want send mail
    $Email->viewVars(array("data" => $data));
                    $Email->template($template)
                        ->emailFormat('html')
                        ->to($reciever)                            
                        ->from(array($mail_from => "Ecotrak"))
                        ->subject($subject)
                        ->send();

I hope this will resolve problem.

Rashid Khan
  • 328
  • 3
  • 12
0

Email could not be sent: SMTP server did not accept the password. See trace

If you are facing that issue and your check everything is fine there is no issue anywhere but you still facing that issue.

Just do this simple process.

  1. Go to your Google Account.
  2. Select Security.
  3. Go down
  4. Click on Less Secure app access
  5. Turn it on

Now check it... your issue will resolve

Ali Nawaz
  • 1
  • 2