Cakephp 2.x Mail connection with Office365 - email

I am developing an application where my client is using Office 365 for his emails , etc... I am trying to connect Cakephp mail with office 365 SMTP but without any success.
Here is my code:
public $default = array(
'from' => array('info#*****.com' => 'Company Name'),
'transport' => 'Smtp',
'host' => 'tls://smtp.office365.com',
'port' => 587,
'username' => 'info#*****.com',
'password' => '*******',
'client' => null,
'log' => true,
'tls' => true
);
The error iam getting is Unable to connect to SMTP server. Also I tried the following hosts with and without tls:
ssl://smtp-mail.outlook.com
Smtp.mail.apac.microsoftonline.com (on this i was getting timeout error)
pod51022.outlook.com
Thanks.

try following :
'public $default = array(
'host' => 'smtp.office365.com',
'port' =>25,
'from' => array('info#*****.com' => 'Company Name'),
'transport' => 'Smtp',
'username' => 'info#*****.com',
'password' => '*******',
'tls'=>true );'
in case it don't work,
try after removing password,
make sure that
email id is authenticated to send anonymous mail on office365.

Related

yii2 mailer smtp connection refused

When setting up my smtp mailer in the config file, it works fine. But if I manually create the SMPT mailer it fails (Connection refused). Can anybody assist?
Yii2 config file:
'components'=[
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email#gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
The following code in my controller does not work:
$mailer = new \yii\swiftmailer\Mailer();
$mailer->transport = new \Swift_SmtpTransport();
$mailer->transport
->setHost('smtp.gmail.com')
->setPort(587)
->setEncryption('tls');
$mailer->transport->setUsername('email#gmail.com');
$mailer->transport->setPassword('password');
and I receive an error message: Connection refused #111
I have tried port 465 on ssl and I receive the same message.
My main reason for doing this is that I have different client accounts, each of which has its own smtp. I therefore need one account per client and I cannot seem to do that via the config file.
Many thanks for your help.
I just tried it worked for me, I did as follow
'components'=[
'mailer' => [ //Your default mailer
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email#gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
],
'mailer2' => [ //Your custom mailer
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'new_email#gmail.com',
'password' => 'new_password',
'port' => 'new_port587',
'encryption' => 'new_tls',
],
]
following is for default config
Yii::$app->mailer->compose()
->setFrom('info#gmail.com')
->setTo('xxx#gmail.com')
->setSubject('Subject')
->setTextBody('Plain text content')
->setHtmlBody("Hello")
->send();
following with custom mailer config
Yii::$app->mailer2->compose()
->setFrom('info#gmail.com')
->setTo('xxx#gmail.com')
->setSubject('Subject')
->setTextBody('Plain text content')
->setHtmlBody("Hello")
->send();
create a component is the fastest solution, otherwise, you can use the parameter to store configuration, and call when needed.

Do you have any idea on how to implement efax using SMTP Mail Driver (MAILGUN)

This is the sample email I received
This is my code:
Laravel 4.2
Controller:
Mail::send('emails.patient.fax-note'){
$message->to('61756041159#efaxsend.com');
$message->to('sunnycris1229#gmail.com', "Sunny");
$message->subject('Test Fax Notes Using smtp.mailgun.org');
$message->from('support#lktconsult.com');
} , "-f support#lktconsult.com");
mail.php setting
'driver' => 'mailgun',
'host' => 'smtp.mailgun.org',
'port' => 587,
'from' => array('address' => "support#lktconsult.com", 'name' => "Hippocamp"),
'encryption' => 'tls',
'username' => "support#lktconsult.com",
'password' => "mypassword",
services.php
'mailgun' => array(
'domain' => 'sandbox9a694deec43645249032794f0b054c82.mailgun.org',
'secret' => 'my key here',
),
My Code works perfectly in the email, but not in efax, because efax only accept the mail if you send it to :61756041159#efaxsend.com and most importantly from: support#lktconsult.com , My problem is, the image I attached is the original email I received in my gmail.. stating that it came from : Received: from mail1.static.mgsend.net (mail1.static.mgsend.net. [104.130.122.1]) thats why efax does not accept the email.

Laravel 4 Mail Connection could not be established with host smtp.gmail.org

I always getting an error when sending an email. I already openned the open_ssl on php.ini . Currently i am using "guzzlehttp/guzzle": "~4.0" for the mail.
Here's my mail.php settings :
'driver' => 'smtp',
'host' => 'smtp.gmail.org',
'port' => 587,
'from' => array('address' => 'tokotonight456#gmail.com', 'name' => 'tonight'),
'encryption' => 'tls',
'username' => '', //i already set the username + pass correctly
'password' => '',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
Mail::send('mail', array('firstname'=>'budi'), function($message) {
$message->to('tokotonight456#gmail.com','lukas aa')->subject('Welcome to the Laravel 4 Auth App!');
});
Use Mandrill driver instead of smtp. Laravel ships with it.
in app/config/mail.php
change this line
'driver' => 'mandrill',
go to https://mandrillapp.com/settings
sign up and create an an api key
create an app/config/services.php configuration fileand add below configurations and mandrill api key
return array(
'mailgun' => array(
'domain' => '',
'secret' => '',
),
'mandrill' => array(
'secret' => 'enter your mandrill api key here',
),
'stripe' => array(
'model' => 'User',
'secret' => '',
),
);

cakephp email issue with some domains

I have cakephp application, and it has no domain name we are accessing using ip.
I am using the following smpt setting to send email
class EmailConfig {
public $smtp = array(
'transport' => 'Smtp',
'from' => array('myemail#otherdomain.com' => 'my name'),
'host' => 'mail.otherdomain.com',//not the same domain from which sending email
'port' => 25,
'timeout' => 30,
'username' => 'myemail#otherdomain.com',
'password' => 'password',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
}
all emails are being sent to any_email # gmail, otherdomain etc
but there is only one specific govt domain(abc.gov.com) who are not receiving email
they may have implemented some security measures, which may prevent my emails to them, what things can I try at my side and how can I debug to get exact error.
I tried to send email where
to = email#abc.gov.com
cc = email#otherdomain.com
the same email is being received by email#otherdomain.com while not by email#abc.gov.com

cake email internal error

So I am debugging some code that someone else wrote and it utilises the cakephp cake email thing. I have never used it before and have never written an email function before either.
When the function executes it outputs cakes standard: "Error: An Internal Error Has Occurred"
as well as this line:
SMTP Error: 535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 h66sm5396348yhb.7 - gsmtp
The code is here:
public function newAppEmail($email_addr, $password) {
$Email = new CakeEmail();
$Email->config('default');
$Email->sender(array('polarontest#gmail.com' => 'Polaron'));
$Email->from(array('polarontest#gmail.com' => 'Polaron'));
$Email->to($email_addr);
$Email->subject('Eligibility Check');
$Email->template('newapp');
$Email->emailFormat('text');
$Email->viewVars(array('name' => $this->request->data['Applicant']['first_name'], 'email' => $this->request->data['Applicant']['email'], 'password' => $password));
$Email->attachments(array(
'Polaron - PL Passport - Info Pack - 2013.pdf' => array(
'file' => APP . 'documents/Email_attachments/Polaron - PL Passport - Info Pack - 2013.pdf',
'mimetype' => 'pdf'),
));
$Email->send();
}
and this is the config file:
<?php
class EmailConfig {
public $default = array(
'transport' => 'Smtp',
'from' => array('email#email.com' => 'company name'),
'sender' => array('email#email.com' => 'company name'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'email#email.com',
'password' => 'password');
public $fast = array(
'transport' => 'Smtp',
'from' => array('email#email.com' => 'Test Mail name sender'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'email#email.com',
'password' => 'password');
}
Can anyone shed some light on what might be wrong and where I should look to fix it?
Well, SMTP Error 535 means that authentication fails, which is easy to find out.
The exception is thrown because of that. So get the right credentials and try again, this is not an issue of the php code but your credentials.
If your login / password is correct, test the configuration:
public $smtp = array(
'transport' => 'Smtp',
'from' => array('email#gmail.com' => 'Name'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'email#gmail.com',
'password' => '**********',
'client' => null,
'log' => false,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);