Yii2 mail in not sending on portal.azure.com - yii2

I have migrate a Yii2 website from Apache server to portal.azure.com windows server. I have checked that mail is not sending on windows server.
Do anyone have any idea, what I have missed in this.
Thanks

I have used send-grid(https://sendgrid.com/) to setup mail system in Yii2 on portal.azure.com. It should be like below:-
'components' => [
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.sendgrid.net',
'username' => 'azure_************#azure.com',
'password' => '***********',
'port' => '25',
//'encryption' => 'tls',
],
],
],

Related

How to configure mail.php and service.php in laravel 9 project when i use Sendinblue smtp service

In development it works perfectly, the emails reach the recipient, but when I display the project in cpanel I get a 500 error when my client presses the send button.
Currently my configuration is like this:
.ENV:
MAIL_MAILER=smtp
MAIL_HOST=smtp-relay.sendinblue.com
MAIL_PORT=587
MAIL_USERNAME=myEmailUserSendinblue
MAIL_PASSWORD=passwordMySendiblueService
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="EmailClient"
MAIL_FROM_NAME="${APP_NAME}"
SENDINBLUE_API_KEY=xxxxxxxxxxxxxxxxxxxxxxx
mail.php:
'mailers' => [
'sendinblue' => [
'transport' => 'sendinblue',
'host' => env('MAIL_HOST', 'smtp-relay.sendinblue.com'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
],
services.php:
return [
'sendinblue' => [
'api_key' => env('SENDINBLUE_API_KEY'),
],
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
'scheme' => 'https',
],
'postmark' => [
'token' => env('POSTMARK_TOKEN'),
],
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
];
Thank you very much in advance, I remain attentive to your comments.
EDIT 1:
I got an error through the laravel logs, it is as follows:
production.ERROR: Unsupported mail transport [sendinblue]. {"exception":"[object] (InvalidArgumentException(code: 0): Unsupported mail transport [sendinblue]. at /home/-------/public_html/vendor/laravel/framework/src/Illuminate/Mail/MailManager.php:157)
[stacktrace]

Yii2 smtp email is not working on godaddy

I have deploy a Yii2 website from one server to godaddy. Its showing an error :-
'If you receive error " Connection could not be established with host smtp.gmail.com [Connection refused #111] "'
I have set the mail configs below:-
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 't********m#gmail.com',
'password' => '***************',
'port' => '465',
'encryption' => 'tls', //depends if you need it
],
],
I resolved it by just commenting the transport tag as below:-
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
//'transport' => [
// 'class' => 'Swift_SmtpTransport',
// 'host' => 'smtp.gmail.com',
// 'username' => 't********m#gmail.com',
// 'password' => '***************',
// 'port' => '465',
// 'encryption' => 'tls', //depends if you need it
// ],
],

Send email from other smtp in yii2

I use swiftmailer to send email from yii2. I get code from websites, but most of them send email from gmail.com. I want to send email from my university email, but it's not working. What's the problem. This is the code:
In 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*/false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.students.del.ac.id',
'username' => 'if414024#students.del.ac.id',
'password' => 'bmelar28',
'port' => '587',
'encryption' => 'tls',
],
],
Remove smtp in 'host' => students.del.ac.id
show below code
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'students.del.ac.id',
'username' => 'if414024#students.del.ac.id',
'password' => 'bmelar28',
'port' => '587',
'encryption' => 'tls',
]
]
Try this : change port number and host
'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*/false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'students.del.ac.id',
'username' => 'if414024#students.del.ac.id',
'password' => 'bmelar28',
'port' => '25',
'encryption' => 'tls',
],
],

Swiftmailer from Advanced Yii 2.0 does not work with gmail

I'm trying to configure swiftmailer in the advanced yii 2.0 template. I've gone through many posts and I understand that there are some issues with gmail. My configuration environment in development is the following:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => gethostbyname('smtp.gmail.com'),
'username' => 'xxx#gmail.com',
'password' => 'xxssxxxx',
'port' => '465',
'encryption' => 'ssl'
]
I've also set the support mail that's used in the controller to the same gmail address in the main-local config shown above.
I've tried switching to a less secure configuration for apps in the gmail account and it did not work and I'm not particularly fond on changing this. I get the following error when I use ssl encryption
connection could not be established with host ... [ #0]
If I don't specify the encryption I get a time out error.
I have OpenSSL support enabled according to my phpinfo file but I cannot make it work. TLS does not work either because if I change the config (port:'587' & encryption='tls') I get the following error
stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Any ideas on how can I fix this? Is this an unfixed issue? Should I use another mailing extension?
The options can be set like this:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => gethostbyname('smtp.gmail.com'),
'username' => 'xxx#gmail.com',
'password' => 'xxssxxxx',
'port' => '465',
'encryption' => 'ssl',
'streamOptions' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]
]
Editor's note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack. Be sure you fully understand the security issues before using this as a solution.
Try using the gmail smtp IP
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => '64.233.171.108',
'username' => 'XXXXXXX#gmail.com',
'password' => 'XXXXXXX',
'port' => '587',
'encryption' => 'tls',
],
Some production servers cannot solve FQDN via DNS servers
For gmail: encryption must be setted to tls, port to 587 and host to smtp.gmail.com (check if your gethostbyname('smtp.gmail.com'), get the correct value) see the sample below:
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'yourUsername#gmail.com',
'password' => 'yourPassword',
'port' => '587',
'encryption' => 'tls',
],
Please check :
Internet connection
email Configuration
This is my configuration. An Email succesfuly send.
'components'=>[
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#app/mail',
'useFileTransport' => false,
'transport' => [
'class'=>'Swift_SmtpTransport',
'host'=>'smtp.gmail.com', //sample
'username'=>'my#emaul.com', //sample email
'password'=>'~!##$%%^&&', // sample password
'port'=>'465', // gmail ssl use port 465,
'encryption'=>'ssl',
],
],
],
I had this issue my oversight being i was connecting with tls as my encryption , while the remote server only supported the older ssl encryption.
All i did was to change my encryption parameter value from "tls" to "ssl" and everything worked.
I hope this helps someone.
Adding streamOptions solved my problems!
'streamOptions' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]

Yii2 SwiftMailer sending email via remote smtp server (gmail)

I want to send emails via my gmail account.
My mailer config:
[
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,//set this property to false to send mails to real email addresses
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'my#gmail.com',
'password' => 'pass',
'port' => '587',
'encryption' => 'tls',
],
]
I wrote command MailController:
<?php
namespace app\commands;
use yii\console\Controller;
use Yii;
/**
* Sanding mail
* Class MailController
* #package app\commands
*/
class MailController extends Controller
{
private $from = 'my#gmail.com';
private $to = 'to#gmail.com';
public function actionIndex($type = 'test', $data = null)
{
Yii::$app->mailer->compose($type, ['data' => $data])
->setFrom($this->from)
->setTo($this->to)
->setSubject($this->subjects[$type])
->send();
}
}
When I'm trying to run: php yii mail
I get: sh: 1: /usr/sbin/sendmail: not found
But why it requires sendmail if I want just SMTP connection to smtp.gmail.com?
I think you have configured the mailer wrongly. Because it is still using the default mail function. From the documentation the configuration should be like below. The mailer should be inside components.
'components' => [
...
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'username',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
],
...
],
One more suggestion is to use port "465" and encryption as "ssl" instead of port "587", encryption "tls".
Yii2 Has different config files for web and console works. So you need to config both of them. Regarding this issue, I had to make mail config file (for example mailer.php) and include it in both config files (web.php & console.php) like:
'components' => [
...
'mailer' => require(__DIR__ . '/mailer.php'),
...
],
Might be useful for someone as reference:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'username',
'password' => 'password',
'port' => 587,
'encryption' => 'tls',
'streamOptions' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]
],
]