Connecting to AWS SES with Laravel - laravel

Currently working on a user registration form which (as expected) sends out an email to the registered user.
The client decided to go with AWS SES, so I have already had this configured.
.env
MAIL_DRIVER=smtp
MAIL_HOST=email-smtp.eu-west-1.amazonaws.com
MAIL_PORT=587
MAIL_USERNAME=my_username
MAIL_PASSWORD=my_password
MAIL_ENCRYPTION=null
Also defined the following credentials:
SES_KEY=keyRetrievedFromMyCredentialsInSES
SES_SECRET=passwordRetrievedFromMyCredentialsInSES
And also telnet email-smtp.eu-west-1.amazonaws.com 587
Trying 52.19.235.197...
Connected to ses-smtp-eu-west-1-prod-345515633.eu-west-1.elb.amazonaws.com.
What could have gone wrong here?

It may not working without ADDRESS and NAME setting.
MAIL_DRIVER=smtp
MAIL_HOST=null
MAIL_PORT=null
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS = 'hello#example.com'
MAIL_FROM_NAME = 'Example'
After change setting in .env. Run config:cache:
php artisan config:cache

Check documentation -> https://laravel.com/docs/7.x/mail
Install guzzle
composer require guzzlehttp/guzzle
Install AWS SDK for php (laravel)
composer require aws/aws-sdk-php
Check values in .env file
MAIL_DRIVER=ses
MAIL_HOST=email-smtp.eu-west-1.amazonaws.com //aws SMTP Settings -> check mail host
MAIL_PORT=465
MAIL_USERNAME=smpt_username //aws SMTP Settings -> click Create My SMTP Credentials
MAIL_PASSWORD=smpt_password //aws SMTP Settings -> click Create My SMTP Credentials
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=your_email //aws Email Addresses -> add email address -> send test email (in sendbox mode you can send email only on same email for testing)
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID= aws_access_key_id //create user or in existing user check access key
AWS_SECRET_ACCESS_KEY= secret_access_key //create user or in existing user check secret key
AWS_DEFAULT_REGION=eu-west-1 //change with your region
AWS_BUCKET=
In config/service.php
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('Secret access key'),
'region' => env('AWS_SECRET_ACCESS_KEY', 'eu-west-1'), // change with your region
],
Clear cache
php artisan config:cache

Related

Connecting Laravel to iRedMail on separate server

I have set up my iredmail server at mail.rys.com (in this example ip 45.65.36.114). i have a website running laravel at rys.com. i also have installed let's encrypt - with separate instances on each server. i am able to send emails and add accounts fine via the provided email programs, but i need laravel to generate these and have had difficulty getting this to validate
i have tried a number of examples but have not had success. i haven't changed anything on the iredmail side and i can send mail from the admin#rys.com account but not via laravel
any help would be greatly appreciated.
Regards,
Peter
Config:
MAIL_DRIVER=smtp
MAIL_HOST=45.65.36.114
MAIL_PORT=587
MAIL_USERNAME=admin
MAIL_PASSWORD=xxxxx
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=admin#rys.com
MAIL_FROM_NAME="admin#rys.com"
Result:
Swift_TransportException (530)
Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first "
Config:
MAIL_DRIVER=smtp
MAIL_HOST=45.65.36.114
MAIL_PORT=587
MAIL_USERNAME=admin
MAIL_PASSWORD=xxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=admin#rys.com
MAIL_FROM_NAME="admin#rys.com"
Result:
stream_socket_enable_crypto(): Peer certificate CN=mail.rys.com' did not match expected CN=45.65.36.114'
Config:
MAIL_DRIVER=sendmail
MAIL_HOST=45.65.36.114
MAIL_PORT=587
MAIL_USERNAME=admin
MAIL_PASSWORD=xxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=admin#rys.com
MAIL_FROM_NAME="admin#rys.com"
Result:
Swift_TransportException
Expected response code 220 but got an empty response
Config:
MAIL_DRIVER=smtp
MAIL_HOST=45.65.36.114
MAIL_PORT=80
MAIL_USERNAME=admin
MAIL_PASSWORD=xxxxx
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=admin#rys.com
MAIL_FROM_NAME="admin#rys.com"
Result:
Connection to 45.65.36.114:80 Timed Out
This was solved in a similar by adding what's below to the mail config. Answer's towards the bottom but it got the job done in Laravel 6
how to fix stream_socket_enable_crypto(): SSL operation failed with code 1
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],

Swift_TransportException Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required "

I am new to Laravel and looking to enhance my skills in using Laravel framework 5.4. But I don't know what to do when I encounter this error: 1/1) Swift_TransportException Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required Is it .
make sure that you are using the mail credential in .env file. i think you try to send mail without using the mail credentials.so,
create credentials on sendgrid or any mail service for send mail and put these credentials in .env file.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=your credentials username
MAIL_PASSWORD=your secret key
MAIL_ENCRYPTION=tls
replace this
'username' => env('ivanedu947#gmail.com'),
'password' => env('password'),
to this
'username' => env('MAIL_USERNAME','miemail#gmail.com'),
'password' => env('MAIL_PASSWORD','password'),
and on php line comand key
php artisan config:cache
and its must be works

send email in laravel 5.4

I Want to send reset password email in laravel,with default laravel auth
first login in mailtrap.io and get username and password,then edit env file such as this:
MAIL_DRIVER=sendmail
MAIL_HOST=mail.moallemmarket.com
MAIL_PORT=587
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
and edit mail.php file such as env,Now I receive We have e-mailed your password reset link! message But don't receive any email in my inbox,I changed ports to 25 ans 2525 But result is same.How I can Solved this problem?
I had no problem coding
The problem with the non-activation of the email was in the cpanel that was solved by sending the ticket
With mailtrap, I use these vars in my .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null

Error occurring in sending mail for Forget password

I have set up laravel 5.6 on server. When I try to use Forget Password, I am gettting error after enter email id:
Class Swift_AddressEncoder_IdnAddressEncoder does not exist
actually, it was working find two days before but now i dont know what happen...I have done thing in it.
below connection in .env:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=SG.EcuUbtbhSbq1IAh**1tPQg.uFah8Jw**7lh10wGpA_CPU01ySmAC26HFylz_BFI
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="Your Trade Log"
MAIL_FROM_ADDRESS=support#y**r**r*a**.com
this is live link for Reset Password: YourTradeLog

Laravel 5 send mail in contact form

I use Laravel 5.1 and want to send the admin of the page a mail with the content of a contact form.
In my .env file I added the following lines:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=admintest#gmail.com
MAIL_PASSWORD=adminpassword
MAIL_ENCRYPTION=tls
In my controller I have the following:
Mail::send('Site::email', ['contactObject' => $contactObject], function ($message) use ($contactObject) {
$message->from($contactObject->email, $contactObject->vorname)->subject('New contact!');
$message->to('admintest#gmail.com');
});
$contactObject == contains the form which was filled out in the form from the user
Desired result:
When admintest#gmail.com receive a email, the sender of the mail should be $contactObject->email
Actual result:
When admintest#gmail.com receive a email, the sender of the mail is admintest#gmail.com
Any ideas what goes wrong? Thank you
Try This:
In Live server you have no need to configure any type of mail service.
You have to just use this:
MAIL_DRIVER=mail
AND remove this code:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=admintest#gmail.com
MAIL_PASSWORD=adminpassword
MAIL_ENCRYPTION=tls
You have to just use in .env file:
MAIL_DRIVER=mail
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xyz#gmail.com
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=tls
After change in .env file, restart service, or use command php artisan config:cache and php artisan config:clear.
Have you configured the global from address in the config?
Specifically here: https://github.com/laravel/laravel/blob/master/config/mail.php#L49
Chances are that you've set that and it's just using that, making these values blank should let you override it.
Failing that, because you're using Gmail to send an email to Gmail, it's likely not letting you spoof the from and is indeed a security feature on their end.

Resources