I attempted to add the javax.mail jar to my plugin to send emails after a post, but I get an exception
com.sun.mail.handlers.text_plain cannot be cast to javax.activation.DataContentHandler java.lang.ClassCastException: com.sun.mail.handlers.text_plain cannot be cast to javax.activation.DataContentHandler at javax.activation.MailcapCommandMap.getDataContentHandler(MailcapCommandMap.java:596) at javax.activation.MailcapCommandMap.createDataContentHandler(MailcapCommandMap.java:550) at javax.activation.DataHandler.getDataContentHandler(DataHandler.java:611) at javax.activation.DataHandler.writeTo(DataHandler.java:315) at javax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:248) at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1268) at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2012) at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1980) at javax.mail.Transport.send(Transport.java:97) at com.gray.stash.hook.StashPostHookEmailSender.sendEmail(StashPostHookEmailSender.java:153) at com.gray.stash.hook.StashPostHookEmailSender.postReceive(StashPostHookEmailSender.java:96) at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter$1.visit(AsyncPostReceiveRepositoryHookAdapter.java:64) at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter$1.visit(AsyncPostReceiveRepositoryHookAdapter.java:59) at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService$8.doInTransaction(DefaultRepositoryHookService.java:398) at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService$8.doInTransaction(DefaultRepositoryHookService.java:392) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131) at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService.visitEnabledHooks(DefaultRepositoryHookService.java:392) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80) at com.atlassian.stash.internal.aop.ProfilingAspect.profileMethod(ProfilingAspect.java:43) at sun.reflect.GeneratedMethodAccessor173.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:61) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke(ThrowsAdviceInterceptor.java:124) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy182.visitEnabledHooks(Unknown Source) at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter.postReceive(AsyncPostReceiveRepositoryHookAdapter.java:59) at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter.onRepositoryPushEvent(AsyncPostReceiveRepositoryHookAdapter.java:55) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:36) at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$2.run(AsynchronousAbleEventDispatcher.java:66) at com.atlassian.sal.core.executor.ThreadLocalDelegateRunnable.run(ThreadLocalDelegateRunnable.java:34) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)
This seems to be a classpath issue that comes up from time to time. So in my search for a solution, I found How to send email from plugin? that seems to cover Jira and Confluence, but I could not find any information on how to accomplish this with stash. Is there something Similar for Stash Plugins that I can access.
I also found atlassian-mail, which seems to be what the answers in the question I found where using. Is this relevant for Stash plugins? If so what do I need to add to pom to include it in my plugin?
As the Atlassian's mentioned, just use MailService. You create a MailMessage
MailMessage message = new MailMessage(toEmails, fromEmailAddress, ccEmails, Sets.<String>newHashSet(), Sets.<MailAttachment>newHashSet(), text, subject, emailHeaders );
Then send it
if (mailService.isHostConfigured()) { MailMessage mailMessage = buildMessage(...); mailService.submit(mailMessage); }
@Colin Thanks for the help. The code sample made it the best answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
MailService in Stash API is only an interface, but there seems to be no implementation. How do I create an implementation? I've seen the examples from Confluence where you have to use a TaskManager, but there seems to be no TaskManager in Stash API. Can you please post a more complete example?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sebastian,
You'll notice all of Stash services are interfaces. That's because the implmentation is internal and you need to import /inject the service before you can use it.
class MyClass { final MailService mailService; public MyClass(MailService mailService) { this.mailService = mailService; } } atlassian-plugin.xml: <component-import key="mail-service" interface="com.atlassian.stash.mail.MailService" /> <component key="myclass" class="com.example.MyClass" />
https://developer.atlassian.com/display/DOCS/Component+Import+Plugin+Module
I hope that helps.
Charles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Take a look at the MailService provided as part of Stash's public API.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the quick response Seb, but it did not give me any clue. I am already running my Stash in debug mode and configure it into Ecplise. Strange thing is it is happening only for the mail ids having '&' in it.
Please help, I tried all possible options (like replacing & with %26 and amp; etc..). Also tried sending as 'R&Dteam@example.com' in to address.
Thanks
Suman
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suman,
We are just using Spring Mail to send the mail. Personally I would try and write a small Java class that sends a message to your mail server and see if that works first. I suspect the problem may lie there and not in Stash directly.
Cheers,
Charles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Charles and Seb. Yes you were correct, problem was at xchange server. I contacted to IT team regarding this and now users in 'R&Dteam' DLs are able to receive the mails. Sorry if I was not clear at begining of my question, I am new user in this world!!
Thanks a lot for promt help and analysis. Hope same will there for any other future issues.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try turn on debug logging: https://confluence.atlassian.com/display/STASH/Stash+debug+logging
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.