I'm trying to set up the Mail plugin with my SES credentials, but I am obviously missing something because I keep getting this error:
Class: javax.mail.NoSuchProviderException
Message: No provider for aws
I've added the following to my Config.groovy:
grails {
mail {
host = "email-smtp.us-east-1.amazonaws.com"
port = 465
username = "XXXXXXXXX"
password = "YYYYYYYYY"
props = [
'mail.transport.protocol': 'aws',
'mail.aws.class': 'com.amazonaws.services.simpleemail.AWSJavaMailTransport',
'mail.aws.user': 'WWWWWWWWWWWW',
'mail.aws.password': 'ZZZZZZZZZZZ'
]
}
}
I've been looking through all the possible tutorials, half of them were from the time SES didn't support SMTP, thats why I have the class reference from the maven repo.
Does anyone know how I can configure this?
This is what I have been using successfully -
grails {
mail {
host = "email-smtp.us-east-1.amazonaws.com"
port = 587
username = "smtp user name"
password = "smtp password"
props = ["mail.smtp.starttls.enable":"true",
"mail.smtp.port":"587"]
}
}
Let me know if the above works
Related
My web application created using Grails 2.4.4 with shiro:1.2.1 and it's working fine. In my application I've created one user with limited permissions called xyzUser.
Now I've a domain, username, password of the active directory. And my requirement is to allow the request from the same and bypass login page and provide all the access of xyzUser.
For that I've tried
org.grails.plugins:ldap:0.8.2
plugins and add following configuration in config.groovy (https://grails.org/plugin/ldap)
ldap {
directories {
directory1 {
url = "ldap://demo.myDomain.in"
base = "ou=demo,dc=myDomain.in"
userDn = "uid=Username,ou=demo,dc=myDomain.in"
password = "Password"
searchControls {
countLimit = 40
timeLimit = 600
searchScope = "subtree"
}
}
}
typemappings = [
my.app.MyTypeMappings
]
}
Now I can't understand that what to do next to fulfill my requirements...
I'm looking for a nice clean example of how to do a pull using lidgit2sharp. I took the example here which does a fetch, but the reference to Credentials is throwing an exception.
using (var repo = new Repository(workingDir, null))
{
Remote remote = repo.Network.Remotes.Add("master", repoUrl);
repo.Network.Fetch(remote,
{
Credentials credentials = new Credentials
{
Username = "username",
Password = "password"
}
});
}
The exception is Cannot create an instance of the abstract class or
interface 'LibGit2Sharp.Credentials'
It's telling you in the error: Credentials is an abstract class, interface, whatever.
Try this:
Credentials credentials = new UsernamePasswordCredentials()
{
Username = "username",
Password = "password"
}
I am trying to send mail using Grails Async Mail API
When I tried for Gmail using below configuration :
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "xxxx#gmail.com"
password = "xxxx"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
in config.groovy, I was able to send mail. When I changed above configuration for a specific mail server as below :
grails {
mail {
host = "xxx"
port = 25
username = "xxx"
props = ["mail.smtp.auth":"false",
"mail.smtp.socketFactory.port":"25",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"true",
"mail.smtp.starttls.enable": "false",
"mail.smtp.starttls.required": "false"]
}
}
I am getting below error :
javax.mail.MessagingException: Could not connect to SMTP host: xxx, port: 25;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
Please provide me some hint, what I am doing wrong in above case.
You can try to do simply following and it should work for you
grails {
mail {
host = "xxx"
port = 25
username = "xxx"
props = ["mail.smtp.auth":"false",
"mail.smtp.socketFactory.port":"25",
"mail.smtp.starttls.enable": "true"]
}
}
I am new with grails and am developing a web application in grails.
In my registration page I am getting the user's email id and I need to send a mail with authentication link.
http://grails.org/plugin/mail
http://grails.org/plugin/email-confirmation
I have referred these pages and many other pages to do this task.
But the problem is, my email is not sending.
I have used
Gmail SMTP server address : smtp.gmail.com
Gmail SMTP username : myid#gmail.com
Gmail SMTP password : -my password-
Gmail SMTP port : 465
Gmail SMTP TLS/SSL required : yes
Mail settings are:
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "myId#gmail.com"
password = "mypassword"
props = [
"mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class": "javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
grails.mail.default.from="noreply#gmail.com"
but at least
sendMail {
to "friend#gmail.com"
subject "Hello "
body 'How are you?'
}
is not working.
The exception occured is
Error 500: Internal Server Error
URI
/MailVerificationDemo/user/signup/form
Class
java.net.ConnectException
Message
Connection refused
Around line 104 of MailMessageBuilder.groovy
101: log.trace("Sending mail ${getDescription(message)}} ...")102: }103:104: mailSender.send(message instanceof MimeMailMessage ? message.mimeMessage : message)105:106: if (log.traceEnabled) {107: log.trace("Sent mail ${getDescription(message)}} ...")
Around line 41 of grails-app/services/grails/plugin/mail/MailService.groovy
38: callable.resolveStrategy = Closure.DELEGATE_FIRST39: callable.call()40:41: messageBuilder.sendMessage()42: }43:44: def getMailConfig() {
Around line 18 of grails-app/controllers/user/UserController.groovy
15: return16: }17:18: mailService.sendMail {19: to userInstance.email20: subject "New User Confirmation"21: html g.render(template:"mailtemplate",model:[code:userInstance.confirmCode])
Around line 195 of PageFragmentCachingFilter.java
192: if (CollectionUtils.isEmpty(cacheOperations)) {193: log.debug("No cacheable annotation found for {}:{} {}",194: new Object[] { request.getMethod(), request.getRequestURI(), getContext() });195: chain.doFilter(request, response);196: return;197: }198:
Around line 63 of AbstractFilter.java
60: try {61: // NO_FILTER set for RequestDispatcher forwards to avoid double gzipping62: if (filterNotDisabled(request)) {63: doFilter(request, response, chain);64: }65: else {66: chain.doFilter(req, res);
Try this it's worked for me.
Notice that: Gmail SMTP TLS/SSL required : yes.
But you don't put "mail.smtp.starttls.enable": "true"
grails.mail.host="smtp.gmail.com"
grails.mail.port=587
grails.mail.username="yourUsernameHere"
grails.mail.password="yourPwdHere"
grails.mail.from="defaultMailFromHere"
grails.mail.props = ['mail.smtp.auth': "true",
"mail.smtp.starttls.enable": "true",
"mail.from":"defaultMailFromHere"]
grails.mail.javaMailProperties = ['mail.smtp.auth': "true",
"mail.smtp.starttls.enable": "true",
"mail.from":"defaultMailFromHere"]
I am trying to send an email from a grails app. I tried with recommended settings using gmail and it worked fine. I sent mail successfully. But I want to override the username and password dynamically. I don't know how can I do it. Can anybody help?
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "faruq#gmail.com" // Want to change dynamically like variable ${branch.mail}
password = "12345" // Want to change dynamically like variable ${branch.pass}
props = [
"mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"
]
}
}
I use this process for overriding the username from the controller
grailsApplication.config.grails.mail.username = Branch.get(2).mail
by this process username successfully changes
here Branch is my domain class and mail is property
but an authentication problem comes up:
javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted
Now what can I do?
You can use an external configuration file - put placeholder values in the main Config.groovy
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "<changeme>"
password = "<changeme>"
props = [
"mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"
]
}
}
and then override them with the correct values in the external config:
grails {
mail {
username = "faruq#gmail.com"
password = "12345"
}
}
To be able to change the credentials dynamically at run time it gets rather more complicated. Under the covers the mail plugin creates a Spring bean which is an instance of JavaMailSenderImpl to handle the actual sending of emails, and this bean is configured by default with static settings from the config. But at runtime this class appears to call its own getUsername() and getPassword() every time it needs to send a message. So you could replace this bean with your own custom subclass of JavaMailSenderImpl that overrides these methods to pull the details from the request context (code example, not tested, and imports/error handling omitted):
src/groovy/com/example/RequestCredentialsMailSender.groovy
class RequestCredentialsMailSender extends JavaMailSenderImpl {
public String getUsername() {
return RequestContextHolder.requestAttributes?.currentRequest?.mailUsername ?: super.getUsername()
}
public String getPassword() {
return RequestContextHolder.requestAttributes?.currentRequest?.mailPassword ?: super.getPassword()
}
}
You'd have to register this bean in your resources.groovy, and duplicate a fair bit of the configuration from the mail plugin itself, which is less than ideal:
grails-app/conf/spring/resources.groovy
beans = {
mailSender(com.example.RequestCredentialsMailSender) {
def mailConf = application.config.grails.mail
host = mailConf.host
port = mailConf.port
username = mailConf.username // the default, if not set in request
password = mailConf.password
protocol = mailConf.protocol
javaMailProperties = mailConf.props
}
}
Now when you need to send mail from a controller you can do
request.mailUsername = Branch.get(2).mail
request.mailPassword = Branch.get(2).mailPassword
sendMail { ... }
Just wanted to verify Ian's answer and expand it.
In the default Config.groovy file I have the added external config line:
grails.config.locations = [
"file:./${appName}-config.groovy",
"classpath:${appName}-config.groovy"
]
....
// and here is the mail config as above
grails{
mail{
....
In the config file at the root level I have my config file: TestApp-config.groovy (where TestApp is the name of my app) as above:
grails {
mail {
username = "faruq#gmail.com"
password = "12345"
}
}
Didn't need anything past this and it worked great.
We can also use replyTo field if our aim is only to get the reply back on specific Email Id. We can dynamically pass an email id to "replyTo" field and can expect an email back on the same.
Example :
asynchronousMailService.sendMail
{
to ["xyz#gmail.com","pqr#gmail.com"]
subject "Subject Text"
if(ccs) cc ["xyz1#gmail.com","pqr1#gmail.com"]
if(bccs) bcc ["xyz2#gmail.com","pqr2#gmail.com"]
if(replyTo) replyTo "xyz#gmail.com"
if(attachBytes) attachBytes attachBytes
}
NOTE: Adding "replyTo" will only allow us to get the emails back on the specified email-id and will not send the email from the configured email.
It was suitable in my use case. Hope it helps !