Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Add support the method sendMail(Config) #78

Open
wureka opened this issue Oct 28, 2017 · 0 comments
Open

Add support the method sendMail(Config) #78

wureka opened this issue Oct 28, 2017 · 0 comments
Assignees

Comments

@wureka
Copy link

wureka commented Oct 28, 2017

the Grails plugin org.grails.plugins:mail currently doesn't support multiple SMTP hosts.
However, there is someone who provides a work around way to reach this request (pls see http://www.stepwise.pl/blog/grails3-multiple-smtp-servers/.
I added the above work around way to asynchronous-mail and failed. the failed exception is as below:

`

2017-10-29 05:59:41.638 DEBUG EmailNotificationService.sendMailUsingPrimaryAccount() : Sending an email from primary account fetapp
2017-10-29 05:59:41.651 ERROR EventBus.accept() : No Session found for current thread

org.hibernate.HibernateException: No Session found for current thread
at org.grails.orm.hibernate.GrailsSessionContext.currentSession(GrailsSessionContext.java:116)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:688)
at org.grails.orm.hibernate.cfg.GrailsHibernateUtil.setObjectToReadWrite(GrailsHibernateUtil.java:325)
at org.grails.orm.hibernate.cfg.GrailsHibernateUtil$setObjectToReadWrite.call(Unknown Source)
at org.grails.orm.hibernate.HibernateGormInstanceApi.setObjectToReadWrite(HibernateGormInstanceApi.groovy:133)
at org.grails.orm.hibernate.AbstractHibernateGormInstanceApi.save(AbstractHibernateGormInstanceApi.groovy:136)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:151)
at org.grails.datastore.gorm.GormEntity$Trait$Helper$save$9.call(Unknown Source)
at grails.plugin.asyncmail.AsynchronousMailMessage.save(AsynchronousMailMessage.groovy)
at grails.plugin.asyncmail.AsynchronousMailMessage.save(AsynchronousMailMessage.groovy)
at org.grails.datastore.gorm.GormEntity$save$0.call(Unknown Source)
at grails.plugin.asyncmail.AsynchronousMailPersistenceService.save(AsynchronousMailPersistenceService.groovy:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1432)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at grails.plugin.asyncmail.AsynchronousMailService.sendAsynchronousMail(AsynchronousMailService.groovy:46)
at grails.plugin.asyncmail.AsynchronousMailService$sendAsynchronousMail.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at grails.plugin.asyncmail.AsynchronousMailService$sendAsynchronousMail.callCurrent(Unknown Source)
at grails.plugin.asyncmail.AsynchronousMailService.sendMail(AsynchronousMailService.groovy:70)
at grails.plugins.mail.SendMail$sendMail.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at com.zebulun.service.EmailNotificationService$$EQZOAklP.sendMailUsingPrimaryAccount(EmailNotificationService.groovy:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springsource.loaded.ri.ReloadedTypeInvoker$2.invoke(ReloadedTypeInvoker.java:133)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1461)
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:216)
at reactor.spring.context.config.ConsumerBeanAutoConfiguration$Invoker.apply(ConsumerBeanAutoConfiguration.java:351)
at reactor.spring.context.config.ConsumerBeanAutoConfiguration$ServiceConsumer.accept(ConsumerBeanAutoConfiguration.java:297)
at reactor.spring.context.config.ConsumerBeanAutoConfiguration$ServiceConsumer.accept(ConsumerBeanAutoConfiguration.java:284)
at reactor.bus.EventBus$3.accept(EventBus.java:317)
at reactor.bus.EventBus$3.accept(EventBus.java:310)
at reactor.bus.routing.ConsumerFilteringRouter.route(ConsumerFilteringRouter.java:72)
at reactor.bus.EventBus.accept(EventBus.java:591)
at reactor.bus.EventBus.accept(EventBus.java:63)
at reactor.core.dispatch.AbstractLifecycleDispatcher.route(AbstractLifecycleDispatcher.java:160)
at reactor.core.dispatch.MultiThreadDispatcher$MultiThreadTask.run(MultiThreadDispatcher.java:74)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Caused by: reactor.core.support.Exceptions$ValueCause: Exception while signaling value: reactor.bus.Event.class : Event{id=null, headers=null, replyTo=null, key=com.zebulun.mail.primary.mail, data=com.zebulun.mail.event.PrimaryMailAccountEvent@13ae6a2d}
at reactor.core.support.Exceptions.addValueAsLastCause(Exceptions.java:127)
at reactor.bus.routing.ConsumerFilteringRouter.route(ConsumerFilteringRouter.java:77)
... 7 common frames omitted
`
Then, I change my code as below:

`

@Selector('com.zebulun.mail.secondary.mail') 
def sendMailUsingSecondaryAccount(SecondaryMailAccountEvent event) {
    log.debug 'Sending an email from secondary account'
    Member.withTransaction{
        asyncMailService.sendMail(extendedMailConfig) {
            multipart true
            from extendedMailConfig.from
            to '[email protected]'
            subject 'Email from Secondary account fetapp'
            text "Hello Secondary Account"
            html '<h1> Hello Secondary Account</h1>'
        }
    }
}

`

And the error becomes as below:

`

No signature of method: grails.plugin.asyncmail.AsynchronousMailService.sendMail() is applicable for argument types: (org.grails.config.PropertySourcesConfig,  com.zebulun.service.EmailNotificationService$_sendMailUsingSecondaryAccount_closure2$_closure4) values: [[host:smtp.gmail.com, from:[email protected], port:465, username:[email protected], ...], ...]
Possible solutions: sendMail(groovy.lang.Closure), findAll()

`

After digging your code, I found AsynchronousMailService doesn't implement the method sendMail(Config)

Is it possible to add the above implementation into next release version?
Thanks.

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

No branches or pull requests

2 participants