Laravel: All RCPT commands were rejected with this error: 503-relay not permitted, authentication required - laravel

I've made a website with Laravel which uses email to notify users of certain things. For testing on my personal computer, I used my gmail account for sending email from te website, which worked perfectly fine. Now I want to launch the website for the public and for the final version I want it to use noreply#mydomain to send email instead of my gmail adress.
Therefore I've set set the environment variables in the .env file like so:
MAIL_DRIVER=smtp
MAIL_HOST=mail1.webyte.eu
MAIL_PORT=587
MAIL_USERNAME=noreply#mydomain
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
The guy from my hosting service told me that this should be correct, however, when I try this, I get the following error:
Swift_TransportException (503) Expected response code 354 but got code
"503", with message "503-All RCPT commands were rejected with this
error: 503-relay not permitted, authentication required 503 Valid RCPT
command must precede DATA"
I've been searching the internet for a few days now and couldn't find anything that works for me...
Does anyone know what I should do here? Thanks!

I figured it out by changing :
MAIL_DRIVER=sendmail

Some servers have particulars settings. For instance, for my server on namecheap I had need to add these vars in .env file
MAIL_FROM_ADDRESS=noreply#mydomain
MAIL_FROM_NAME=NoReply

I also fix this error by including the following on my .env file:
MAIL_DRIVER=sendmail

This error is raise from your SMTP email service provider. Laravel uses SwiftMailer to send email. So you can catch the error by using this below method
try {
Mail::send('emails.contact-message', [
'msg' => $request->body,
'name' => $request->name,
'email' => $request->email,
],
function ($mail) use($request) {
$mail->from($request->email, $request->name);
$mail->to('support#domain.com')->subject('Contact Message');
}
);
// Catch the error
} catch(\Swift_TransportException $e){
if($e->getMessage()) {
dd($e->getMessage());
}
}

This question is a bit dated, but I think my answer may be useful to someone else.
I was getting OP's error message with my organization's Microsoft Exchange server using Laravel & SwiftMailer.
It turned out that I could send email to internal emails (the same domain name), but not external ones. The error message provided by SwiftMailer was misleading and sent me looking in the wrong direction for a while.
I would recommend testing your SMTP server with internal (same domain name) and external emails using telnet as another debugging step, which will provide accurate error messages:
https://www.jasonsamuel.com/2009/12/17/send-email-via-telnet-to-test-an-exchange-server/
To resolve this issue, I had to get my organization's IT team involved. More info:
https://github.com/swiftmailer/swiftmailer/issues/1181#issuecomment-490920874

Related

Laravel 6 send mail

I have an issue with authentication while sending mail with Laravel smtp driver.
.env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=account#gmail.com
MAIL_FROM_ADDRESS=account#gmail.com
MAIL_PASSWORD=app_password
MAIL_ENCRYPTION=tls
It gives the following error:
"530-5.7.0 Authentication Required. "
2-Factor auth is enabled and app password is used;
Also tried with SSL on 465, same error;
Config is flushed every time .env is changed;
Everything in config/mail corresponds to .env;
SO all typical solutions are not working. What else may cause this problem?
I have also tried using smtp.vivaldi.net with vivaldi account, it authenticates, but gives an error:
"no valid recipients"
while recipient email is surely valid, which is also strange for me.
I've stumbled across this multiple times already, hence I do not remember the exact error-message which I received but here is my assumption.
Google has an option called "less secure apps" which you need to enable in order to send directly mails through their SMTP interface. Can you check if this flag is disabled and try to enable it?
https://support.google.com/a/answer/6260879
In addition to that google is slowly deprecating this feature. Starting from Mid 2020 you'll be not able to enable this flag anymore and they will completely remove this in 2021.
Reference: https://gsuiteupdates.googleblog.com/2019/12/less-secure-apps-oauth-google-username-password-incorrect.html
Firstly, you need to setup 2 step verification here google security.
An App Password link will appear and you can get your App Password to insert into below "MAIL_PASSWORD". More info on getting App Password here
MAIL_DRIVER=smtp
MAIL_FROM_ADDRESS=noreply#talhaf.com
MAIL_FROM_NAME=System
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=YOUR_GMAIL#gmail.com
MAIL_PASSWORD=YOUR_GMAIL_CREATED_APP_PASSWORD
MAIL_ENCRYPTION=tls
Don't forget to clear cache with :
php artisan config:cache
Problem was that I messed up with config/mail.php.
I wrote
'username' => env('email'),
'password' => env('app_password'),
Instead of
'username' => env('MAIL_USERNAME','email'),
'password' => env('MAIL_PASSWORD','app_password'),

Expected response code 235 but got code 535 laravel send email using office365 smtp

I want to send email using my office365 smtp credentials in laravel application. i have make changes in my .env file for email settings as below:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=info#***.com
MAIL_PASSWORD=*******
MAIL_ENCRYPTION=tls
while i am trying to send email i got error like
Failed to authenticate on SMTP server with username \"info#omoyyc.com\" using 2 possible authenticators. Authenticator LOGIN returned Swift_TransportException: Expected response code 235 but got code \"535\", with message \"535 Incorrect authentication data\r\n\"
my email sending code is as below
Mail::send(array(), array(), function ($m) use ($templatecontent) {
$m->from('customerservice#****.com', 'TEST');
$m->to('test#gmail.com', 'Test')
->subject($templatecontent['subject'])
->setBody($templatecontent['content'], 'text/html');
});
Can anyone guide me what is the issue and how to solve this issue?
I don't know if the cause is the same as OP, but I got the same error. I fixed it by enclosing the password with double quotes.
I'm assuming that the parsing fails when the password contains special characters.
I had the same issue.
I used Gmail SMTP, with less secure apps enabled & 2-factor auth disabled, and nothing worked. And surprisingly as #jessij mentioned, setting the password in double-quotes worked.
Do below in .env file:
Replace: MAIL_PASSWORD=yourpassword
With: MAIL_PASSWORD="yourpassword"
my problem is same dude, but my problem has been solved to try it :
Go to https://myaccount.google.com/security#connectedapps
Take a look at Security menu -> Apps with account access menu.
You must turn the option "Allow less secure apps" ON.
If you already followed this step, try again your project. and if it still doesn't work, please continue this steps :
Visit https://accounts.google.com/UnlockCaptcha
Click continue button
Good Luck dude!
If your password contains special characters like "john##3398", put this in " ". Then clear your php artisan cache using
php artisan config:cache
Then start your php artisan serve.

Namecheap\Mailgun - receiving email

I am wondering how to setup namcheap and maligun to receive emails. Currently I am able to send emails with my laravel application through maligun, but I am not sure how to setup maligun to receives replies?
I have seen the options of setting up routes to receive emails to some wanted enpoint, but currently I am not receiving anything on maligun, so I have nothing to forward. I am getting the message:
This is the mail system at host eforward3e.registrar-servers.com.
I'm sorry to have to inform you that your message could not be
delivered to one or more recipients. It's attached below.
For further assistance, please send mail to postmaster.
If you do so, please include this problem report. You can delete your
own text from the attached returned message.
The mail system
: unknown user:
"support#my-domain.com"
Final-Recipient: rfc822; support#my-domain.com
Original-Recipient: rfc822;support#my-domain.com Action: failed
Status: 5.1.1 Diagnostic-Code: X-Postfix; unknown user:
"support#my-domain.com"
How should I set this up?
Hope you register your domain at mailgun, if not then do it here. Once your domain register follow below steps:
1) Get domain and API Key from Mailgun > Doamins > Domain Information page
2) Setup config/services.php:
'mailgun' => array(
'domain' => 'YOURDOMAINNAME',//Place your register domain name here...
'secret' => 'API Key',//Place your API Key here...
),
3) Setup .env:
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=USERNAME
MAIL_PASSWORD=YOURPASSWORD
MAIL_ENCRYPTION=tls
4) Check with sending mail from laravel application.
That's it...

Laravel's Mail notification won't send, but Laravel's Mail::Raw will

I have configured my SMTP server correctly in Laravel's env file, and can successfully send an email using Mail::raw e.g.
Mail::raw("This is a test message", function ($message)
{
$message->from(env("MAIL_ORDER_ADDRESS"), 'Orders');
$message->to('user#example.com');
$message->subject('Test Message');
});
However, when I use a laravel 5.3 mail notification, no email is received (nor is an error generated). I have tested the same notification code locally using mail trap and the notifications work correctly.
I can't understand how if the mail server is working and can be used with Mail::raw, it doesn't automatically work with notifications when I have tested locally and confirm they are coded correctly.
Note: Using shared hosting on NameCheap.
Any ideas?
FIXED: It was because I had not configured "From" in config/mail.php and because the domains didn't match, it wasn't set.
The opposite situation is occurring for me. I have the MAIL_DRIVER=mail set within the .env file.
I have set MAIL_FROM_ADDRESS & MAIL_FROM_NAME within the .env file and viewed the app/config/mail.php
Mail::raw is sending out email correctly via the Postfix logs but any emails sent via the new Laravel 5.3 Notifications is not working. No errors or any information writing to the logs.
There appears to be some other issue occurring.
I had the same issue. During testing for Mail::raw, i had set MAIL_ENCRYPTION to empty.
When I set MAIL_ENCRYPTION=tls for notify email, it started working.

MailGun Laravel - Cant send to gmail

I have mailgun setup and working with my custom domain name, as in, I can send test emails to me#mydomain.com but when I try to send to gmail I get the following error.
ClientException in RequestException.php line 107:
Client error: `POST https://api.mailgun.net/v3/mydomain.com/messages.mime` resulted in a `400 BAD REQUEST` response:
{
"message": "Please activate your Mailgun account. Check your inbox or log in to your control panel to resend the act (truncated...)
My mailgun account is setup to work with my domain name correctly and my custom email address doesn't match my site domain name and mail gets delivered to it from mailgun no problems...
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=mydomain.com
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=postmaster#mydomain.com
MAIL_PASSWORD=ljhasdlkfhklahsdfklhklasdhflkhasdlkfhkhasdkflh
MAILGUN_SECRET=key-asdflkhjaklsdfkljaslkdfjlkjasdfkj
MAIL_FROM=postmaster#mydomain.com
MAIL_ENCRYPTION=tls
Its weird that when trying to send to a gmail address it gives tells me I need to activate my mailgun account but when sending to a custom domain name address its works perfectly, anyone have any ideas.. Here is the function I am using to send the emails
Mail::send('emails.recontact', ['title' => $title, 'content' => $content], function ($message) use ($request){
$message->from( 'me#mysite.ie', $request->input('name') );
$message->to('myname#gmail.com');
$message->subject("Website Enquiry");
});
You may need to activate you account.
Please login to your mailgun account and make sure there is no a yellow message on the top of the screen that said:
"Please activate your account to start sending emails. We sent an activation email to {your_email}. Resend activation. Update email address."
This solved my problem :)
I am working on mailgun but i faced different problem when recipient reply mail stores instead of delivered

Resources