Script Sending mails with Gmail: Failed to authenticate on SMTP server - email

I am having some hard time getting my PHP script to send emails with a SMTP Gmail account. I am using PHP and Symfony2 SwiftMailer, but it seems that the problem lies with my Gmail account configuration. In my logs, I end up with the following error message:
"ERROR - Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username "new.user.name#gmail.com" using 1 possible authenticators"
Luckily, I had another Gmail account working with another application, seemlessly. Rescuing these parameters (user and password) on my new box, eveything works just fine.
in parameters.yml I have (working fine):
parameters:
mailer_transport: gmail
mailer_host: ~
mailer_user: old.user.account#gmail.com
mailer_password: old-password
And here is the version giving auth error message:
parameters:
mailer_transport: gmail
mailer_host: ~
mailer_user: new.user.account#gmail.com
mailer_password: new-password
Needless to say I have checked, rechecked and checked yet again user and password.
I reviewed my Gmail account settings under "Forwarding and POP/IMAP" in my new account: I could find nothing about SMTP.
Searches made me aware some captcha policy may interfere with SMTP accounts. I read here that I should try to enter a captcha phrase, which I do here, and get the nice message:"Account access enabled", "Please try signing in to your Google account again from your new device or application."
Trying again. No luck.
All this is happening from my local dev environment (both OK mails, and NOT OK mails).
How I could get to use SMTP with a newly created Gmail Account ? Any idea ?

Actually, double-checking my inbox, I saw I received a mail from Google explaining someone was trying to enter my account. There, I found a link to the configuration parameter I was looking for:
https://www.google.com/settings/security/lesssecureapps
==> I just had to check: "Make my account less secure.", and was able to get mails sent.
In the mean time, I have found that Gmail SMTP service is getting pretty unrelyable and introduces captcha every now and again (here). I seems there is not much you can do about it. On the other hand, I read stronger passwords seem to help in some cases (here).
I must also say that with a newly created account, I was not able to get this working. Even unchecking the "make my account overly secure" option. It really looks like Gmail is phasing out its SMTP service.
UPDATE
I wanted to mention that there are some excellent and free (or very, very cheap for high volumes) alternatives for sending emails. For example, you could check Mandrill, SendGrid or Amazon SES, among others.

Using the link https://www.google.com/settings/security/lesssecureapps gave me the message: this setting is disabled by your administrator.
I had to go to admin.google.com and login with the same account details and look for the same setting there. Full url was https://admin.google.com/AdminHome#ServiceSettings/notab=1&service=securitysetting&subtab=lesssecureappsaccess
Then the first link worked, so also there I enabled less secure apps. Now I was able to use Gmails SMTP.

Maybe this helps someone: I had the same encounter with gmail, but in my case, when I logged into the gmail account that I configured in my code as SMTP mail sender user, I was greeted by a warning message saying that somebody tried to use my user and pass and that attempt was blocked (hence my error message). It asked me to confirm if that was me or not, so after I clicked the 'That was me' button and tried my code again all worked fine.

Making my account less secure helped me https://myaccount.google.com/lesssecureapps

Related

Jira email notifications not working, but test e-mail is working

We have an on-premise hosted Jira 6.0.8. We have set up an outgoing mail server using a Gmail account and used the send test e-mail feature to successfully send an e-mail out.
Our problem is with e-mail notifications. We are not getting any at all. We have gone through troubleshooting docs https://confluence.atlassian.com/jirakb/troubleshoot-notifications-in-jira-203394737.html here but have not been able to find the solution.
Here is what we have already tried;
Ensured user profile 'My Changes setting' was set to 'Notify Me'
Ensured Notification scheme was correct and associated with the project
Ensured Project Notification email was set to the same as the outgoing mail server Gmail address
Checked the 'Mail Queue' after making a comment on an issue and saw waiting messages in it for the correct issue. These then disappeared from the queue without error within 60 seconds, indicating that they had been sent.
Enabled DEBUG logging under 'Logging and Profiling' for the outgoing mail server and com.atlassian.jira.service and com.atlassian.jira.service.services.DebugService. We reviewed the log file and saw nothing that indicated error but did see the log of the MailqueueService sending the e-mail.
have used the 'Notifcation Helper' tool and it verified that the user would receive the appropriate notification indicating notifcation scheme and permission are set up ok.
Still the notification e-mail is not received.
There was a point made in the troubleshooting link above
Check that your Base URL is set to a domain / IP which your SMTP server will accept. Example: Google apps accounts must have a matching base url to their Google Apps domain.
However, our Adminsistration> System>General Configuration>Base Url for Jira is something like http://myservername:8880 since it is internal self-hosted. This did not cause a problem with the test mail. Could this be an issue for the notification e-mails?
Any help would be greatly appreciated.

when sending a verify email request from keycloak via sendgrid, the resulting url is wrongly encoded

I have a keycloak (4.4.0-Final) installation.
Scenario:
sendgrid is configured as mail agent (and test mail sending is ok)
I create a new user in keycloak admin console and I pass it the action "verify email"
I get an email with a link to verify my email address, but when I click the link, I get the error "We're sorry...
An error occurred, please login again through your application."
I now have a closer look at the URL and I see 2 times = => http://keycloakurl/.....login-actions/action-token?key=eyJhbGciOiJIUzUx...&client_id=client-...
When I change = to = , the url works.
Does someone know if this is a bug in sendgrid, or a bug in the keycloak templates?
I know you have moved ahead with Mailjet but I would like to share my solution here as it may help others. I noticed this issue only happens if Email Tracking is enabled at SendGrid side. Try after disabling all tracking configurations under Setting -> Tracking screen.
The issue was not keycloak, but sendgrid (ref: https://issues.jboss.org/browse/KEYCLOAK-8536). We fixed the issue by dropping sendgrid and going to mailjet.

Mail routing with mailgun

I'm setting mailgun route to xx#me.com to forward an email to a server at http://xxx:7000/reply.
I tested already the email route and it's fine as well as the server is up both in browser and using curl. However sending an email to xx#me.com still nothing happens.
There is already a similar question but nobody answered:
Can't recieve incoming mail with Mailgun
There are a few requirements for handling incoming emails with Mailgun.
Your account must be verified (email/SMS message)
The domain or subdomain must be added to the account.
SPF & DKIM must be verified and have MX records configured with Mailgun's values. Details for DNS record information
Route filters configured with the recipient domain or subdomain matching. (Example: Domain "bar.com" is added to the account. The expression can match_recipient("foo#bar.com"). If a subdomain is added, then it will need to match the subdomain, e.g. match_recipient("foo#mg.bar.com"))
The error from the linked question would be due to one of the above requirements wasn't fulfilled. A rejection of "550 5.7.1 Relaying denied" from Mailgun's incoming mail servers indicates a domain or subdomain has MX records pointed toward Mailgun's but the domain does not exist within an account.
**Disclaimer I work at Mailgun
I know this is 6 months old, but since I spent 4 hours trying to figure this out, I will share my solution:
There is another cause of the 5.7.1 Relaying denied message: My mailgun account wasn't verified. I saw someone suggest this but I figured they just meant that I had to verify the address I was forwarding to. Nope, when I logged in today I saw a banner at the top saying click here to resend your verification email. I did that, it went through a text message verification process, and all immediately started working!
I know this is quite a stale thread, but I also wanted to chime in here in hopes of saving folks a few hours of their life trying to solve the "550 5.7.1 Relaying denied" caper.
For me? It was what has plagued me on several occasions. I was able to verify via Gmail > 'Settings' > 'Accounts and Import' > 'Add another email address' only after I disconnected from my software-based VPN (Private Internet Access).
[Your sigh or wince here]
Now, go get it... make it happen. ;-)
If you're using MailGun with cPanel (for example, after following this tutorial) and you're getting the 550 5.7.1 Relaying denied error, make sure you're using the MailGun SMTP credentials given after adding your domain (as opposed to your MailGun username and password as the documentation suggests). That was the origin of my own problem.
Another reason for this error code may well be that you are trying to send stuff over SMTP whereas you've indicated on the sending properties of mailgun settings for your domain that you want to use the API...

Send email from my custom mailgun SMTP address

Sorry if I have not understood something but (I believe) I have searched enough for this.
First things first: I have successfully set up my domain (mydomain.gr) which has been verified.
I have created a custom SMTP address (contact#mydomain.gr).
I have created a route which forwards everything sent at *#mydomain.gr to my personal Gmail address.
Test 1: If I send an email from an external address (something#something.eu) to contact#mydomain.gr it is forwarded to my personal Gmail. OK!
Test 2: If I send from contact#mydomain.gr to any external address (something#something.eu) I get the error Free accounts are for test purposes only. Please upgrade or add the address to authorized recipients in Account Settings. Of course the password is correct while sending. Otherwise another error is raised.
I think I have missunderstood some things...
So here comes my question:
How can I send email from my custom SMTP email address? (I do not wish to upgrade my account since this -free- Mailgun account will handle very small amount of emails. So, 10K are more than enough for me.)
OK. After some emails with the mailgun team I finally figure it out!
All I had to do was to upgrade my account (just enter credit card info). Now I can send email from contact#mydomain.gr to anyone.
Thank you mailgun!
I have also contacted Mailgun for the issue and get response back within few minutes:
This error occurs whenever utilizing either a sandbox domain or a free account without inviting users called Authorized Recipients.
Sandbox domains always require Authorized Recipients. With free plans, which are intended for test usage, all custom domains require Authorized Recipients. With upgraded plans, which are intended for production usage, custom domains no longer require Authorized Recipients.
Please take a look at the following Help Center article for more information about the Authorized Recipient process:
https://help.mailgun.com/hc/en-us/articles/217531258-Authorized-Recipients
Then I have add the Authorize Recipients and it works like a champ!

Sending locally sent email (with sendmail) to Google Apps Mail Server

I have a domain, call it mydom.com.
A while ago I started using Google App's email server. I set up MX and the rest of the stuff records as Google wanted, and all is working well since.
On www.mydom.com I have a website, DNS and still running mail server (which basically doesn't do much).
Among other things, on www.mydom.com, I have some contact form - basic php page that takes user's input and sends it to predefined email address at mydom.com. It sends it with php's sendmail function.
My issue is - all those email that get sent from localhost to *#mydom.com (by php's function, or possible by some cron jobs reporting some issues) DO NOT go to Google's email servers but instead get picked up by localhost and it's mail server.
So far, I was resolving this issue by setting up a new mail account at Google account, which was basically calling my local mail server by it's IP address, logging into old, abandoned email account and pulling those misplaced emails to the new, #mydom.com account at Google App.
Obviously I'm missing some entry either in local DNS, host file or something..
Does anyone know how do I fix it?
Hey, the same question was asked here: https://serverfault.com/questions/102647/sendmail-to-local-domain-ignoring-mx-records-part-2
and the answer to it works for me, don't forget to include the dot after the domain!
If it doesn't work to the test call and see how the mail traces.
best of luck, svullo