<div dir="ltr">We have the built in EmailProvider, but it doesn&#39;t have a generic sendMail method, which it should have. You can create a JIRA issue to request that.<div><br></div><div>In the mean time you can package your provider as a module instead of a jar to have more control of the classpath.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 23 November 2015 at 13:57, Ataraxus <span dir="ltr">&lt;<a href="mailto:atx@binaryninja.de" target="_blank">atx@binaryninja.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    Here is the code and the stacktrace just in case, maybe there is a
    better way to send email: <br>
    <br>
    
    private void send(UserModel user, AuthenticationFlowContext context,
    String subject, String textBody, String htmlBody) throws
    EmailException {<br>
            try {<br>
                String address = user.getEmail();<br>
                Map&lt;String, String&gt; config =
    context.getRealm().getSmtpConfig();<br>
    <br>
                Properties props = new Properties();<br>
                props.setProperty(&quot;mail.smtp.host&quot;, config.get(&quot;host&quot;));<br>
    <br>
                boolean auth = &quot;true&quot;.equals(config.get(&quot;auth&quot;));<br>
                boolean ssl = &quot;true&quot;.equals(config.get(&quot;ssl&quot;));<br>
                boolean starttls =
    &quot;true&quot;.equals(config.get(&quot;starttls&quot;));<br>
    <br>
                if (config.containsKey(&quot;port&quot;)) {<br>
                    props.setProperty(&quot;mail.smtp.port&quot;,
    config.get(&quot;port&quot;));<br>
                }<br>
    <br>
                if (auth) {<br>
                    props.put(&quot;mail.smtp.auth&quot;, &quot;true&quot;);<br>
                }<br>
    <br>
                if (ssl) {<br>
                    props.put(&quot;mail.smtp.socketFactory.port&quot;,
    config.get(&quot;port&quot;));<br>
                    props.put(&quot;mail.smtp.socketFactory.class&quot;,
    &quot;javax.net.ssl.SSLSocketFactory&quot;);<br>
                }<br>
    <br>
                if (starttls) {<br>
                    props.put(&quot;mail.smtp.starttls.enable&quot;, &quot;true&quot;);<br>
                }<br>
    <br>
                String from = config.get(&quot;from&quot;);<br>
    <br>
                Session session = Session.getInstance(props);<br>
    <br>
                Multipart multipart = new MimeMultipart(&quot;alternative&quot;);<br>
    <br>
                if (textBody != null) {<br>
                    MimeBodyPart textPart = new MimeBodyPart();<br>
                    textPart.setText(textBody, &quot;UTF-8&quot;);<br>
                    multipart.addBodyPart(textPart);<br>
                }<br>
    <br>
                if (htmlBody != null) {<br>
                    MimeBodyPart htmlPart = new MimeBodyPart();<br>
                    htmlPart.setContent(htmlBody, &quot;text/html;
    charset=UTF-8&quot;);<br>
                    multipart.addBodyPart(htmlPart);<br>
                }<br>
    <br>
                Message msg = new MimeMessage(session);<br>
                msg.setFrom(new InternetAddress(from));<br>
                msg.setHeader(&quot;To&quot;, address);<br>
                msg.setSubject(subject);<br>
                msg.setContent(multipart);<br>
                msg.saveChanges();<br>
                msg.setSentDate(new Date());<br>
    <br>
                Transport transport = session.getTransport(&quot;smtp&quot;);<br>
                if (auth) {<br>
                    transport.connect(config.get(&quot;user&quot;),
    config.get(&quot;password&quot;));<br>
                } else {<br>
                    transport.connect();<br>
                }<br>
                transport.sendMessage(msg, new InternetAddress[]{new
    InternetAddress(address)});<br>
            } catch (Exception e) {<br>
                throw new EmailException(e);<br>
            }<br>
        }<br>
    <br>
    connect/auth<br>
    <br>
    JBWEB000309: type JBWEB000066: Exception report<br>
    <br>
    JBWEB000068: message request path:
    /auth/realms/MYAPP/protocol/openid-connect/auth<br>
    <br>
    JBWEB000069: description JBWEB000145: The server encountered an
    internal error that prevented it from fulfilling this request.<br>
    <br>
    JBWEB000070: exception<br>
    <br>
    java.lang.RuntimeException: request path:
    /auth/realms/MYAPP/protocol/openid-connect/auth<br>
       
org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:75)<br>
    JBWEB000071: root cause<br>
    <br>
    org.jboss.resteasy.spi.UnhandledException:
    java.lang.NoClassDefFoundError: javax/mail/Multipart<br>
       
org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:364)<br>
       
org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:232)<br>
       
org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:208)<br>
       
org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:556)<br>
       
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:523)<br>
       
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:125)<br>
       
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)<br>
       
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)<br>
       
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)<br>
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)<br>
       
org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:61)<br>
    JBWEB000071: root cause<br>
    <br>
    java.lang.NoClassDefFoundError: javax/mail/Multipart<br>
       
de.MYAPP.auth.authenticator.MYAPPEmailAuthenticatorFactory.create(MYAPPEmailAuthenticatorFactory.java:27)<br>
       
de.MYAPP.auth.authenticator.MYAPPEmailAuthenticatorFactory.create(MYAPPEmailAuthenticatorFactory.java:19)<br>
       
org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:124)<br>
       
org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:97)<br>
       
org.keycloak.authentication.AuthenticationProcessor.authenticate(AuthenticationProcessor.java:650)<br>
       
org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.browserAuthentication(AuthorizationEndpoint.java:315)<br>
       
org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.buildAuthorizationCodeAuthorizationResponse(AuthorizationEndpoint.java:265)<br>
       
org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.build(AuthorizationEndpoint.java:123)<br>
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
       
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)<br>
       
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)<br>
        java.lang.reflect.Method.invoke(Method.java:606)<br>
       
org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:168)<br>
       
org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269)<br>
       
    org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227)<br>
       
org.jboss.resteasy.core.ResourceLocator.invokeOnTargetObject(ResourceLocator.java:158)<br>
       
    org.jboss.resteasy.core.ResourceLocator.invoke(ResourceLocator.java:106)<br>
       
org.jboss.resteasy.core.ResourceLocator.invokeOnTargetObject(ResourceLocator.java:153)<br>
       
    org.jboss.resteasy.core.ResourceLocator.invoke(ResourceLocator.java:91)<br>
       
org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:541)<br>
       
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:523)<br>
       
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:125)<br>
       
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)<br>
       
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)<br>
       
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)<br>
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)<br>
       
org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:61)<br>
    JBWEB000071: root cause<br>
    <br>
    java.lang.ClassNotFoundException: javax.mail.Multipart<br>
        java.net.URLClassLoader$1.run(URLClassLoader.java:366)<br>
        java.net.URLClassLoader$1.run(URLClassLoader.java:355)<br>
        java.security.AccessController.doPrivileged(Native Method)<br>
        java.net.URLClassLoader.findClass(URLClassLoader.java:354)<br>
        java.lang.ClassLoader.loadClass(ClassLoader.java:425)<br>
        java.lang.ClassLoader.loadClass(ClassLoader.java:358)<br>
       
de.MYAPP.auth.authenticator.MYAPPEmailAuthenticatorFactory.create(MYAPPEmailAuthenticatorFactory.java:27)<br>
       
de.MYAPP.auth.authenticator.MYAPPEmailAuthenticatorFactory.create(MYAPPEmailAuthenticatorFactory.java:19)<br>
       
org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:124)<br>
       
org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:97)<br>
       
org.keycloak.authentication.AuthenticationProcessor.authenticate(AuthenticationProcessor.java:650)<br>
       
org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.browserAuthentication(AuthorizationEndpoint.java:315)<br>
       
org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.buildAuthorizationCodeAuthorizationResponse(AuthorizationEndpoint.java:265)<br>
       
org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.build(AuthorizationEndpoint.java:123)<br>
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
       
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)<br>
       
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)<br>
        java.lang.reflect.Method.invoke(Method.java:606)<br>
       
org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:168)<br>
       
org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269)<br>
       
    org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227)<br>
       
org.jboss.resteasy.core.ResourceLocator.invokeOnTargetObject(ResourceLocator.java:158)<br>
       
    org.jboss.resteasy.core.ResourceLocator.invoke(ResourceLocator.java:106)<br>
       
org.jboss.resteasy.core.ResourceLocator.invokeOnTargetObject(ResourceLocator.java:153)<br>
       
    org.jboss.resteasy.core.ResourceLocator.invoke(ResourceLocator.java:91)<br>
       
org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:541)<br>
       
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:523)<br>
       
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:125)<br>
       
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)<br>
       
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)<br>
       
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)<br>
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)<br>
       
org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:61)<br>
    <br>
    <div>Am 23.11.15 um 13:32 schrieb Ataraxus:<br>
    </div><div><div class="h5">
    <blockquote type="cite">
      <pre>Hey,

I&#39;m writing my custum login provider which works great so far, but i 
stumbled upon a dependency issue:
I wan&#39;t to use mail in my authenticator, but when the authenticator gets 
actually loaded I get an class not found exception.
Somehow is java.mail.* not available in the classpath of providers which 
are dropped in the configuration/providers path.
How can i use these dependencies? I could include them into my jar, but 
i guess thats not the &quot;right&quot; way.

Thanks
_______________________________________________
keycloak-user mailing list
<a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a>
</pre>
    </blockquote>
    <br>
  </div></div></div>

<br>_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br></blockquote></div><br></div>