title: Micronaut and Java Mail API
body: <p>We are trying to migrate parts of our monolith to microservices and we decided to go with micronaut. We are extracting now an email service which given some inputs will render email and talk with an SMTP server to send them.</p>
  
  <p>For that, we use Java Mail which seems to have some problems when we try to create a GraalVM docker image. Has anyone managed to get this right or is it simply impossible to make it work?</p>
  
  <p>Some additional information:</p>
  
  <p><strong>Dockerfile:</strong></p>
  
  <pre><code>FROM oracle/graalvm-ce:19.2.0 as graalvm
  COPY . /home/app/email-service
  WORKDIR /home/app/email-service
  RUN gu install native-image
  RUN native-image --no-server -cp build/libs/email-service-*.jar
  
  FROM frolvlad/alpine-glibc
  EXPOSE 8080
  COPY --from=graalvm /home/app/email-service .
  ENTRYPOINT ["./email-service"]
  </code></pre>
  
  <p><strong>native-image.properties:</strong></p>
  
  <p>Some other "lazy" initializations are in place for JDBC driver, redis, kafka, and thymeleaf.  </p>
  
  <pre><code>Args = --initialize-at-run-time=io.micronaut.views.thymeleaf.ThymeleafFactory \
         --initialize-at-run-time=io.micronaut.views.thymeleaf.ThymeleafViewsRenderer \
         --initialize-at-run-time=io.micronaut.views.velocity.VelocityViewsRenderer \
         --initialize-at-run-time=io.micronaut.configuration.lettuce.session.$RedisHttpSessionConfigurationDefinition \
         --initialize-at-run-time=io.micronaut.configuration.kafka.embedded.KafkaEmbedded \
         --initialize-at-run-time=oracle.jdbc.driver.OracleDriver \
         --initialize-at-run-time=java.sql.DriverManager \
         --initialize-at-run-time=org.hibernate.jpa.HibernatePersistenceProvider \
         --initialize-at-run-time=com.sun.mail.util.MailLogger \
         -H:IncludeResources=logback.xml|application.yml \
         -H:Name=email-service \
         -H:Class=com.acme.MySuperDuperApplication
  </code></pre>
  
  <p><strong>Micronaut Version:</strong> 1.2.0<br>
  <strong>Java Mail Version:</strong> 1.6.2 (<code>com.sun.mail:javax.mail:1.6.2</code>)</p>
  
  <p><strong>Native Image Compilation Error:</strong></p>
  
  <pre><code>Warning: Aborting stand-alone image build. com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of com.sun.mail.util.MailLogger are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
  Detailed message:
  Trace: 
      at parsing javax.mail.internet.MailDateFormat.access$000(MailDateFormat.java:149)
  Call path from entry point to javax.mail.internet.MailDateFormat.access$000(): 
      at javax.mail.internet.MailDateFormat.access$000(MailDateFormat.java:149)
      at javax.mail.internet.MailDateFormat$AbstractDateParser.parse(MailDateFormat.java:426)
      at javax.mail.internet.MailDateFormat.parse(MailDateFormat.java:251)
      at java.text.DateFormat.parse(DateFormat.java:364)
      at freemarker.core.JavaTemplateDateFormat.parse(JavaTemplateDateFormat.java:49)
      at freemarker.core.JavaTemplateDateFormat.parse(JavaTemplateDateFormat.java:33)
      at freemarker.core.BuiltInsForMultipleTypes$dateBI$DateParser.parse(BuiltInsForMultipleTypes.java:204)
      at freemarker.core.BuiltInsForMultipleTypes$dateBI$DateParser.get(BuiltInsForMultipleTypes.java:167)
      at freemarker.ext.beans.HashAdapter.get(HashAdapter.java:73)
      at freemarker.ext.beans.HashAdapter$1$1$1.getValue(HashAdapter.java:124)
      at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
      at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
      at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
      at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
  </code></pre>