Namecheap\Mailgun - receiving email - laravel

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...

Related

Error sending email using Gmail SMTP with Laravel

I'm trying to send mails from my webserver using Laravel 6 like this:
Mail::send('feedback', ['email' => $email, 'text' => $text], function($message) use ($receiver)
{
$message->to($receiver, 'The receiver')->subject('New Feedback');
});
I added my login information into my .env file according to this page from google:
https://support.google.com/mail/answer/7126229?hl=de
my .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxx#gmail.com
MAIL_PASSWORD=my_gmail_login_password
MAIL_ENCRYPTION=tls
but I keep getting this error message:
Expected response code 250 but got code "530", with message "530-5.7.0 Authentication Required. Learn more at
530 5.7.0 https://support.google.com/mail/?p=WantAuthError
It looks like I would have used wrong credentials but I'm able to login with these credentials in gmail.
I also enabled insecure apps in my gmail settings.
I also tried to solve it by creating an app password and using it instead of my gmail password.
Nothing worked.
Does someone have an idea what I'm doing wrong?
when you want to send email from gmail you have to change some settings in gmail account.
Step 1: Configure your Google Account
Login to your Google Email Account and click on Google Account Button. This button is display when you click on the profile picture in your Gmail Dashboard as shown
Once you are on My Account Page then click on Security and scroll down to the bottom and you will find ‘Less secure app access’ settings. Click on the radio button to set it ON.
I think this link is helpful to you
https://medium.com/#agavitalis/how-to-send-an-email-in-laravel-using-gmail-smtp-server-53d962f01a0c
I could solve it by changing
MAIL_DRIVER=smtp
to
MAIL_DRIVER=sendmail
now I don't get any errors logged and everything seems to be working fine, but the mails don't get delivered to the mail address where they should be.

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'),

How to set up mailgun with laravel 5.7?

I am trying to set up mail sending with mailgun on my deployed laravel application. I am able to send email verification emails, but I can't send to my email. For example:
Notification::route('mail', 'admin#mywebsite.org')
->notify(new Feedback($user->email, $subject, $message));
When I was using mailtrap.io to test my mail sending it worked perfectly.
My .env file looks like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAILGUN_SECRET=key-<key>
MAIL_USERNAME=postmaster#sandbox<somenums>.mailgun.org
MAIL_PASSWORD=<mypass>
MAIL_ENCRYPTION=tls
When I try to send the email it brings this error: Expected response code 250 but got code "554", with message "554 Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings. "
welcome to SO.
Please have a deeper look at the Laravel official documentation where you can find everything you need to set up the mailgun driver.
Mailgun Driver
To use the Mailgun driver, first install Guzzle, then set the driver option in your config/mail.php configuration file to mailgun. Next, verify that your config/services.php configuration file contains the following options:
'mailgun' => [
'domain' => 'your-mailgun-domain',
'secret' => 'your-mailgun-key',
],
After updating your conf you have to change the MAIL_DRIVER env variable from smtp to mailgun. All the other settings for username, password and so on are not required.

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!
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

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