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

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!



Solution 1:[1]

I figured it out by changing :

MAIL_DRIVER=sendmail

Solution 2:[2]

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

Solution 3:[3]

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

MAIL_DRIVER=sendmail

Solution 4:[4]

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('[email protected]')->subject('Contact Message');
     }

   );
 // Catch the error
 } catch(\Swift_TransportException $e){
    if($e->getMessage()) {
       dd($e->getMessage());
    }             
 }

Solution 5:[5]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Joshua Oluikpe
Solution 2 Rudy Flores
Solution 3 MEDZ
Solution 4 sta
Solution 5 Ajility