I am working on a Multi-tenant SaaS application where each organisation have separate databases and have their own SMTP details in database.
Now i am queuing all the bulk-emailing activity. Now the problem is how can i load the dynamic SMTP details for the laravel queue.
Currently my queue is working fine but its picking the default SMTP details from .env File
i even tried by setting changing Config details in mailable _construct method. But its not working.
The mailer will be getting values from the config/mail.php class. Change the key values from the ENV function to a custom function which will then determine the correct SMTP details to use for the email.
Pass the email configuration settings as an argument when the job is pushed to the queue, so that the job has access to the correct settings at the time of execution.
Related
I'm currently having trouble with the password reset mail created by make:auth in Laravel 5.6. My app is hosted on Heroku. In my local environment everything works fine. I have set the right values in the config vars in Heroku, same in my local .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myMail#gmail.com
MAIL_PASSWORD=bla
MAIL_ENCRYPTION=tls
I have read here that I have to hard-code the values inside app/mail.php instead of referencing the .env file because Heroku wouldn't recognize/understand this reference
'password' => env('MAIL_PASSWORD')
But then my data would be visible inside the GitHub repo.
What am I doing wrong here?
EDIT:
The accepted answer is the way to go, one should use an Add-On for sending mails in Heroku. Still I found a way to make it work with gmail after setting up sendgrid ;)
- Use `Port 465 with ssl` as encryption.
- Allow `less secure apps` access to my account.
- Visit `http://www.google.com/accounts/DisplayUnlockCaptcha` and sign in with your Gmail username and password.
After these steps, it worked.
Maybe this is helpful for others.
EDIT2:
I migrated Laravel from version 5.x to 8 and I ran into problems again, so I had to change my approach again with gmail.
I had to:
- Allow `less secure apps` access to my account.
- Enable two step verification and create an App Password like in the accepted answer of this question: https://stackoverflow.com/questions/42558903/expected-response-code-250-but-got-code-535-with-message-535-5-7-8-username
- Change Port back to 587 and tls again
- Visit `http://www.google.com/accounts/DisplayUnlockCaptcha` and sign in with your Gmail username and password.
Don't use Gmail in production¹.
Gmail isn't designed to act as an SMTP gateway for your application. Instead, use one of the many mail addons that Heroku recommends. Mailgun and SendGrid are both very popular options, but there are lots of others.
These tools are designed to send mail for applications. They'll be a lot less likely to reject your mail and, when configured properly, make it a lot less likely for your mail to get caught in spam filters. Most of them have walkthroughs for setting things up, and I encourage you to follow them. Make sure not to skip the SPF and DKIM anti-spam features.
I have read here that I have to hard-code the values inside app/mail.php instead of referencing the .env file because Heroku wouldn't recognize/understand this reference
'password' => env('MAIL_PASSWORD')
This is incorrect.
You say that you've set config variables on Heroku, and that populates the environment. The .env file is just a convenient local workaround for doing the same thing. Whichever mail addon you choose will automatically set one or more environment variables for you, and you should use those in your code.
¹You probably shouldn't be using it in development, either, but it's less of a problem there. I urge you to use something like Mailtrap (cloud) or Mailcatcher (local) instead.
I'm currently having trouble with the password reset mail created by make:auth in Laravel 5.6. My app is hosted on Heroku. In my local environment everything works fine. I have set the right values in the config vars in Heroku, same in my local .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myMail#gmail.com
MAIL_PASSWORD=bla
MAIL_ENCRYPTION=tls
I have read here that I have to hard-code the values inside app/mail.php instead of referencing the .env file because Heroku wouldn't recognize/understand this reference
'password' => env('MAIL_PASSWORD')
But then my data would be visible inside the GitHub repo.
What am I doing wrong here?
EDIT:
The accepted answer is the way to go, one should use an Add-On for sending mails in Heroku. Still I found a way to make it work with gmail after setting up sendgrid ;)
- Use `Port 465 with ssl` as encryption.
- Allow `less secure apps` access to my account.
- Visit `http://www.google.com/accounts/DisplayUnlockCaptcha` and sign in with your Gmail username and password.
After these steps, it worked.
Maybe this is helpful for others.
EDIT2:
I migrated Laravel from version 5.x to 8 and I ran into problems again, so I had to change my approach again with gmail.
I had to:
- Allow `less secure apps` access to my account.
- Enable two step verification and create an App Password like in the accepted answer of this question: https://stackoverflow.com/questions/42558903/expected-response-code-250-but-got-code-535-with-message-535-5-7-8-username
- Change Port back to 587 and tls again
- Visit `http://www.google.com/accounts/DisplayUnlockCaptcha` and sign in with your Gmail username and password.
Don't use Gmail in production¹.
Gmail isn't designed to act as an SMTP gateway for your application. Instead, use one of the many mail addons that Heroku recommends. Mailgun and SendGrid are both very popular options, but there are lots of others.
These tools are designed to send mail for applications. They'll be a lot less likely to reject your mail and, when configured properly, make it a lot less likely for your mail to get caught in spam filters. Most of them have walkthroughs for setting things up, and I encourage you to follow them. Make sure not to skip the SPF and DKIM anti-spam features.
I have read here that I have to hard-code the values inside app/mail.php instead of referencing the .env file because Heroku wouldn't recognize/understand this reference
'password' => env('MAIL_PASSWORD')
This is incorrect.
You say that you've set config variables on Heroku, and that populates the environment. The .env file is just a convenient local workaround for doing the same thing. Whichever mail addon you choose will automatically set one or more environment variables for you, and you should use those in your code.
¹You probably shouldn't be using it in development, either, but it's less of a problem there. I urge you to use something like Mailtrap (cloud) or Mailcatcher (local) instead.
We are developing Joomla website and have to do Send grid configurations. We have set everything as per guided in official site.
We are getting following issue when sending the email from joomla backend.
"SMTP Error! Could not connect to SMTP host."
this is most likely host-related. First make sure your component is not the issue try sending an email from the user manager.
If it goes through, then your component is not using Joomla configuration properly
If it doesn't (which I would expect) it's just a problem with your server configuration,
check firewall, spam settings, try to send email from the command line...
Does anyone know why Magento 1.4 fails to send email notifications for a new order and account activation ?
when I submit the Contact us form it gives the below error.
Unable to submit your request. Please, try again laterAny idea/suggestion on this will be highly appreciated.
More info please. Is this on a Linux box, Windows, etc... Also check the php configuration SMTP settings. Like any php app, email is handed off to the host system, or to server designated in php.ini. Do you have a known working SMTP server to access?
First thing you need to check is whether email communication is disabled in the admin panel.
i am having a joomla site, i hosted it in my own lap, using no-ip, the problem is mail function is not working,what may be the problem? how can i solve it?
This is configured in the Administration Control Panel, in the "Server" tab, mail settings. Default is to use PHP mail - since PHP is usually configured by the hosting provider to send mail without knowing any additional parameters. So for local installation you need to ensure that either your PHP is configured to send emails, or use the Sendmail or SMTP options in Joomla (and configure them there).
I hope this helps.