Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

From Address Not Correct #63

Open
aaronhunter1088 opened this issue Jun 7, 2024 · 8 comments
Open

From Address Not Correct #63

aaronhunter1088 opened this issue Jun 7, 2024 · 8 comments

Comments

@aaronhunter1088
Copy link

I am using the grails mail service to send mail and I am noticing that when running in production environment, the from address is using the username defined in the settings and not what I define in the sendMail closure.

This is my closure:

mailService.sendMail {
    to params.recipientEmail as String
    from “noreply@mixology.com”.  <--- What I expect in either environment. Only present in development env
    subject "Testing Emails"
    body view:"/emails/specificEmail",
              model: [ “model” ]
}

I have tried this in two separate applications and neither are working.

Additionally, I would like to use an email alias and that is also not working. I have tried using my alias account and it works just fine in normal situations, but not with the grails mail plugin. I suspect it's falling under the same issue. The from address supplied to the closure uses my username defined in the settings.

One question I have: I have tried the following closure to hide the email, to show a "name" instead, only revealing the email if I click on the name, but the from address only results in the following: "Mixology aaronhunte@gmail.com". The from address is still visible. Is this something I can control using the plugin? Or is this a mail server setting I need to enable?

mailService.sendMail {
    to params.recipientEmail as String
    from “Mixology noreply@mixology.com”.  <--- Does not hide the email address
    subject "Testing Emails"
    body view:"/emails/specificEmail",
              model: [ “model” ]
}

I have provided screen shots of my environment, and the two emails. (Note: The name, test userr, is correct. I updated it one day and just never changed it)

When running in development: From email is correct.
Development Email

When running in production: I'd expect the from to be "noreply@mixology.com". Instead it is using my username defined in the settings.
Production Email

Mail Settings:
Mail Settings

My environment:
App Status
Plugins

@sbglasius
Copy link

sbglasius commented Jun 7, 2024

@aaronhunter1088 isn't the format Name <some@email.com> for an email address? I have not tested it in your case, but I believe it is.

I think I see the problem. When you use GMail as your SMTP it will force your sender to be that of the GMail account. Sendgrid, AWS or any other service should be useful.

@aaronhunter1088
Copy link
Author

@aaronhunter1088 isn't the format Name <some@email.com> for an email address? I have not tested it in your case, but I believe it is.

I think I see the problem. When you use GMail as your SMTP it will force your sender to be that of the GMail account. Sendgrid, AWS or any other service should be useful.

@sbglasius This still feels like a plugin issue. Why should it matter what SMTP server I use (GMail, or Live, or etc.) The values I supply in the closure should remain independent from the settings values given. Also, I mentioned I have tried with two programs. The other program not mentioned here, uses GMail Services for their email, however the email still has the business domain, not GMail. I shouldn't need to open a new GMail account just to end up forwarding those emails to my primary one.

@sbglasius
Copy link

@aaronhunter1088
See this article: https://support.google.com/mail/answer/22370?hl=en - Your Google account has to have the email verified (through Gmail) before you can use it. Perhaps that is the reason. I don't see why the mail plugin should rewrite the from: address, as it simply uses javax.mail (https://javaee.github.io/javamail/) - there is no magic going on.

@aaronhunter1088
Copy link
Author

@aaronhunter1088 See this article: https://support.google.com/mail/answer/22370?hl=en - Your Google account has to have the email verified (through Gmail) before you can use it. Perhaps that is the reason. I don't see why the mail plugin should rewrite the from: address, as it simply uses javax.mail (https://javaee.github.io/javamail/) - there is no magic going on.

@sbglasius Both emails, the main and alias, are verified. I can send and reply to both from my phone or laptop. It is only when I use the grails plugin where I notice it strictly uses the username from the settings. I have written tests as well that does verify the From address is what I set, and it passes, so that makes it more frustrating that when I actually use the service to send mail, it does not show the proper From address. I am including the Test Report and the entire test for one that returns a 200 response specifically, since it validates the proper From address is being used.

TestReport.txt

@sbglasius
Copy link

@aaronhunter1088 Ok, perhaps your From format is wrong?

mailService.sendMail {
    to params.recipientEmail as String
    from “Mixology noreply@mixology.com”.  <--- The correct format is "Mixology <noreply@mixology.com>"
    subject "Testing Emails"
    body view:"/emails/specificEmail",
              model: [ “model” ]
}

@aaronhunter1088
Copy link
Author

@sbglasius While I appreciate the appropriate format to provide a name to be visible instead of the From address, the expected From address still is not correct. It is using the username from my settings, and not "noreply@mixology.com".

TestEmail

@sbglasius
Copy link

@aaronhunter1088 this small example shows that it works: https://github.com/sbglasius/mail-plugin-example

The bottom two messages are with sbglasius@gmail.com, the middle two are with soeren@glasius.dk (alias on sbglasius@gmail.com) and the top two are obviously not right, as they are sent with sbglasius@gmail.com (as expected).

image

I often find it enlightening to simply my problem to a very tiny project. In this case you can start it with ./gradlew bootRun -Dgrails.mail.username=yourmail@gmail.com -Dgrails.mail.password=itsabigsecret

Your test, which mostly seems to test the mocking framework as pretty much everything in there is mocked out. I suggest that you change it to an integration-test, using the green-mail plugin.

While I did not fix your problem, I believe that the Mail plugin is working as intended, and that the error lies hidden somewhere in a configuration. If not, the code is open and you're more than welcome to submit a pull-request with a bugfix.

@aaronhunter1088
Copy link
Author

aaronhunter1088 commented Jun 12, 2024

@sbglasius I cloned your project, replaced the configurations with my username and password to connect, updated the sendMailFrom method to test different From addresses, and they all say they're sent from the username configured in the settings. It appears the plugin is not working as I expect, at least with host smtp.gmail.com. Keeping this open since the problem persists, at least using the specified host.
I tried in both development and production environment, and neither sent from the proper From address, which is moving backwards as it is working in development environment as expected in both my applications where I am using the grails mail plugin, but not production environment.

Here is a screenshot of one of the emails that sets the subject specifically to be sent from a specific From address, but from the screenshot, that is not what I experience.

Edit: Btw, I do appreciate all the help. I wasn't expecting this and is greatly appreciated. :)

grails-mail-bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants