I am using SendGrid for the first time. In this regard, I looked at other issues about JI, but no one worked for me.
I use Eclipse and Amazon Web Services - Lambda. The library I'm using is https://github.com/sendgrid/sendgrid-java
My scenario: I use the Lambda function to send emails to users who have selected email.
Here is my code:
Email email = new Email(); email.addTo(DEV_TO_EMAIL); email.addToName("XXXXX"); email.setFrom(DEV_FROM_EMAIL); email.setSubject("XX"); email.setText("sms_message"); try { sendgrid.send(email); } catch (SendGridException e) { e.printStackTrace(); if(DEBUG) logger.log("Exception while sending Email"); }
Here is the Exception:
Could not initialize class org.apache.http.impl.conn.ManagedHttpClientConnectionFactory: java.lang.NoClassDefFoundError java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.impl.conn.ManagedHttpClientConnectionFactory at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:493) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:138) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:114) at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726) at com.sendgrid.SendGrid.<init>(SendGrid.java:71) at xx.LambdaFunction.handleRequest(LambdaFunction.java:183) at xx.LambdaFunction.handleRequest(LambdaFunction.java:1)
I tried to follow this suggestion in SO, Sendgrid Java Doesn't work in Maven , but it also led to the same error.
Any suggestions on what to do? Let me know if you need anything else.
source share