0
votes

I'm trying to send an email on completion of the EMR job. I have used libraryDependencies += "com.sun.mail" % "javax.mail" % "1.6.2" in my sbt dependencies.

I tested the email sending in local and it works fine but the same job fails in the EMR job with the below exception:

20/11/21 04:28:12 WARN mail: expected resource not found: /META-INF/javamail.default.address.map
javax.mail.NoSuchProviderException: No provider for smtp
    at javax.mail.Session.getProvider(Session.java:545)
    at javax.mail.Session.getTransport(Session.java:744)
    at javax.mail.Session.getTransport(Session.java:725)
    at javax.mail.Session.getTransport(Session.java:782)
    at javax.mail.Transport.send0(Transport.java:249)
    at javax.mail.Transport.send(Transport.java:124)
    at util.EmailUtil.sendEmail(EmailUtil.java:44)
    at util.EmailUtil.sendMail(EmailUtil.java:59)
    at com.here.places.rule.testing.EmailTester$.main(EmailTester.scala:16)
    at com.here.places.rule.testing.EmailTester.main(EmailTester.scala)
    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.apache.spark.deploy.yarn.ApplicationMaster$$anon$4.run(ApplicationMaster.scala:706)

The code used is ` public class EmailUtil { public static void sendEmail(Session session, String toEmail, String subject, String body){ try { MimeMessage msg = new MimeMessage(session); //set message headers msg.addHeader("Content-type", "text/HTML; charset=UTF-8"); msg.addHeader("format", "flowed"); msg.addHeader("Content-Transfer-Encoding", "8bit");

        msg.setFrom(new InternetAddress(toEmail));
        msg.setReplyTo(InternetAddress.parse(toEmail));
        msg.setSubject(subject, "UTF-8");
        msg.setText(body, "UTF-8");

        msg.setSentDate(new Date());

        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail, false));
        System.out.println("Message is ready");
        Transport.send(msg);

        System.out.println("EMail Sent Successfully!!");
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

public static void sendMail() {
    Properties props = System.getProperties();
    props.put("mail.smtp.host", "***");
    props.put("mail.smtp.port", "25");

    Session session = Session.getInstance(props, null);
    sendEmail(session, "***","SimpleEmail Testing Subject", "SimpleEmail Testing Body");
}

}`

1
Try Amazon Simple Email Service located here.Elliott Frisch
Thanks. I will try Amazon Simple Email Service. But still, I want to know what exactly is the problem here. I logged into the data node and pinged the smtp host and it was successful. Also, telnet host-name 25 also successful. This confirms that there is no network issue.Rajashree Gr
I can only refer you here.Elliott Frisch

1 Answers

0
votes

The application is build using SBT and used the below merge strategy.

assemblyMergeStrategy in assembly := {
  case PathList("META-INF", xs @ _*) => MergeStrategy.discard
  case x => MergeStrategy.first
}

The fat jar created didn't have the necessary META_INF files from the javax.mail jar and it was causing an issue. For testing purpose, I manually copied the META-INF files from javax.mail jar to the fat jar and it worked.