Microsoft 365 SMTP authentication failure [SMTP: Invalid response code received from server - smtp

i am getting following error but all settings are correct no issue but advice if someone has done smtp setting of 365 office
connectors are added in admin center and changed the max sp as advised
authentication failure [
SMTP: Invalid response code received from server
(code: 535, response: 5.7.3 Authentication unsuccessful
[LO2P265CA0220.GBRP265.PROD.OUTLOOK.COM]
)
]
here is code:
<?php
require_once "Mail.php";
$from = '<info#domain.com>';
$to = '<dodmaon#domani.com>';
$subject = 'Insert subject here';
$body = "Hello world! this is the content of the email";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'smtp.office365.com',
'SMTPSecure' => 'tls',
'port' => '587',
'StartTLS' => true,
'auth' => true,
'username' => 'info#domain.com',
'password' => '321password'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo '<p>'.$mail->getMessage().'</p>';
} else {
echo '<p>Message successfully sent!</p>';
}
?>

If you are very sure that all settings including Username and Password are correctly configured, then the problem is a Microsoft thing. And how to solve it is this;
you need to login from a browser (https://accounts.live.com) using the username and password you have configured in your application.
While logged in, go to "security and privacy" and look for the link to "recent activity" alternatively, you can just enter this address after logging in to go there directly https://account.live.com/Activity.
From here you should see the attempts from the email you are sending from and click the option "This was me" next/under to it.
Also consider disabling 2step authenticator if on.
When you have completed this, wait a few minutes and then try again.
Let me know if this worked. :)

Related

Yii2 SwiftMailer .eml files created but with wrong names & file_put_contents Permission denied

The problem is when I'm trying to "send" the email it's failing with the message
file_put_contents(/some/path//frontend/runtime/debug/mail/20180413-165142-0679-0633.eml):
failed to open stream: Permission denied
The file is being created but with a slightly different name, for example 20180413-165142-0666-8857.eml (I can see it by time). I have no idea what is going on. Any suggestions?
Config file is simple:
common/main-local.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
And sending by this:
Yii::$app->mailer->compose('order', ['order' => $this])
->setTo(Yii::$app->params['adminEmail'])
->setFrom(Yii::$app->params['adminEmail'])
->setSubject('New order #' . $this->id)
->send();
And 'adminEmail' => 'admin#example.com',
Thanks for your attention.

Connecting to remote mysql server using sequelize [duplicate]

I have Xampp installed in windows and I am creating an application using Laravel 5.3. I am trying to execute a query on another server on local network but when I try to do that the MySql server authenticate the user that is on my local server with is (username: "root" && password:"") while the remote server have (username: "root" && password:"root") and i don't know why. here is my laravel connection under config/database.php
'smsgateway' => [
'driver' => 'mysql',
'host' => '**.**.**.**',
'database' => 'database',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
how i use the connection
$smsgateway = \DB::connection('smsgateway');
// dd($smsgateway);
$smsgateway->statement($sql);
I tried to connect using a native PHP code but I face the same problem here is my code
$servername = "**.**.**.**;
$username = "root";
$password = "root";
try {
$conn = new PDO("mysql:host=$servername;dbname=database", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
it gives me
Connection failed: SQLSTATE[HY000] [1045] Access denied for user
'root'#'myIPAddress' (using password: YES)
You need to grant the permission to access the database from local
Use these commands and then revert , help url here
grant remote access of MySQL database from any IP address
In my own case, due to valid security concerns, i opted to develop an API to connect to the remote mysql database. I did this using php's CURL library. On the foreign domain (the domain you are connecting from), i did a curl post to the database domain (the domain holding the database).
From here its quite easy as all you do is save the $_POST parameters using prepared statements on the local database. I just thought to put this answer here. It might help someone out there
For example, you would like to save two values to the remote database.
<?php
$array = array('key1' => $key1, 'key2' => $key2);
$url = 'www.site.com/api.php';
#do curl post to remote database
$ch = curl_init();
if ($ch !== false) {
curl_setopt($ch, CURLOPT_URL, $url); //this is the url of the domain where the database is being hosted
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); //if you are returning json
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
#on the #url script, all you do is access the values via `$_POST`. example: `$_POST['key1'];`
?>
Don't use root in password. Password field should be blank on your XAMPP set up.

Codeigniter stopped sending mails from gmail smtp on wamp server windows 10

The code i am posting was working fine for 2 months. Now, from some reason it stopped sending mails.
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'system#gmail.com',
'smtp_pass' => 'xxxxxxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
//za da mi ispraka na sevisniot mail i da mozam da sledam dali ispraka izvestai dokolku oni stiklirale isprakanje
$this->email->clear(TRUE); //za reset pred sekoe novo prakanje od jamkata
$this->email->set_newline("\r\n");
$this->email->from('doNotReply', '');
$this->email->to('service#gmail.com');
$this->email->subject($subjectStart . ' izvestaj');
$this->email->message('');
$this->email->attach('D:/wamp64/www/dica/assets/iEksel/'. $filename);
if ( ! $this->email->send()){
$myfile = fopen("mail.txt", "a") or die("Unable to open file!");
$txt = $this->email->print_debugger();
fwrite($myfile, $txt);
fclose($myfile);
}
The debugger outputs this errors:
The following SMTP error was encountered: 0 Unable to send data: AUTH LOGINFailed to send AUTH LOGIN command. Error: Unable to send data: MAIL FROM:< doNotReply >< pre>from: The following SMTP error was encountered: < br />Unable to send data: RCPT TO:< br />< pre>to: < /pre>The following SMTP error was encountered: < br />Unable to send data: DATA< br />< pre >data: The following SMTP error was encountered: < br />Unable to send data: User-Agent: CodeIgniter.
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Does anyone has an idea why this code that worked perfectly for 2 months, now fails to work?
You dont need this smtp code for server-side.
for server-side this much code is enough:
$this->load->library('email');
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->to($this->input->post('emailtxt'));
$this->email->cc($this->input->post('cctxt'));
$this->email->from($fromEmail['user_email']);
$this->email->subject($this->input->post('smailtxt'));
$this->email->message($this->input->post('tamailtxt'));
$this->email->attach($pathfile);
$this->email->send();
and for client side the code you used looks find. Issue must be if smtp user email and password is changed or check php.ini file in wamp.
Instead of smtp used smtps in array.
$config = Array(
'protocol' => 'smtps',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'system#gmail.com',
'smtp_pass' => 'xxxxxxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);

Is my yii2 smtp configuration correct?

I have the following smtp configuration, but I'm not sure since sometimes I face ssl timed out while sending an email.
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => true,
],
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#backend/mail',
'useFileTransport' => false,//set this property to false to send mails to real email addresses
//comment the following array to send mail using php's mail function
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'in-v3.mailjet.com',
'username' => 'a3027c3xxx',
'password' => 'c838779xxx',
'port' => '465',
'encryption' => 'ssl',
],
],
Then I use like this
$message = Yii::$app->mail->compose();
$message->setTo(Yii::$app->params['adminEmail'])
->setFrom(Yii::$app->params['adminEmail'])
->setTo("mymail#gmail.com")
->setSubject('Password Reset')
->setHtmlBody($this->renderAjax('//email/_konten',['hello'=>"To black" ,'konten'=>'this is konten','link'=>Yii::$app->params['baseurl'].'lupapass/chpass?&q=empty','textbutton'=>'Click this link']))
->send();
and the result is sometime I face timed out.
But if I send directly from swiftmailler class like below code it sucessfully send 100 email without any ssl timed out
$transport = \Swift_SmtpTransport::newInstance('in-v3.mailjet.com', 465)
->setUsername('myusername')
->setPassword('s3cr3t')
->setEncryption('ssl');
$mailer = \Swift_Mailer::newInstance($transport);
$message = \Swift_Message::newInstance('Password Reset')
->setFrom(array('no-reply#myweb.com' => 'My Web'))
->setTo(array('some#one.com'))
->setBody($this->renderAjax('//email/_konten',['hello'=>"To black" ,'konten'=>'this is konten','link'=>Yii::$app->params['baseurl'].'lupapass/chpass?&q=empty','textbutton'=>'Click this link']))
->setContentType("text/html")
;
$result = $mailer->send($message);
If you ask how my ssl timed out here is my question link
How to solve Swift_TransportException Connection to ssl Timed Out error?
So I start thinking is this ssl timed out because my configuration? or different sending method? from first example and second example?
in common\config\main-local.php there is a mailer => [] and mail => [] is this neccessary?
an can you please explain what is useFileTransport really?
Thanks in advance.
PS. I have already use any thirdparty and port configuration but still facing ssl timed out issue.
According to Gmail SMTP config when you are using encryption ssl or tls use port 587 instead of 465

Steps to send mail using sendgrid mailer function in yii2?

I am trying to get the mail using sendgrid in Yii 2 but it doesn't seem to work.Can any one tell me steps of sendgrid in yii2 .
You can use https://github.com/bryglen/yii2-sendgrid#yii-2-bryglen-sendgrid
Installation:
composer require --prefer-dist bryglen/yii2-sendgrid "*"
common/config/main.php
'components' => [
...
'sendGrid' => [
'class' => 'bryglen\sendgrid\Mailer',
'username' => 'your_user_name',
'password' => 'your password here',
//'viewPath' => '#app/views/mail', // your view path here
],
...
],
To send an email, you may use the following code:
$sendGrid = Yii::$app->sendGrid;
$message = $sendGrid->compose('contact/html', ['contactForm' => $form]);
$message->setFrom('from#domain.com')
->setTo($form->email)
->setSubject($form->subject)
->send($sendGrid);