I am trying to automate emails for my app and from the SendGrid documentation, I could write the java code to do the same. Here is the java code,
import com.sendgrid.*;
import com.sendgrid.helpers.mail.Mail;
import com.sendgrid.helpers.mail.objects.*;
import java.io.IOException;
public class TwiMail {
public static void main(String[] args) throws IOException {
Email from = new Email("ss@gmail.com");
Email to = new Email("vv@outlook.com");
String subject = "Sending subject";
Content content = new Content("text/html", "<em>easy</em> to do with <strong>Java</strong>");
Mail mail = new Mail(from, subject, to, content);
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.POST);
request.setEndpoint("mail/send");
request.setBody(mail.build());
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getHeaders());
System.out.println(response.getBody());
}
}
But I am getting some unexpected errors like
Exception in thread "main" javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Upon further research, I could get the crux of the problem via this StackOverflow page which is about importing the URL certificate to the java cacerts but I don't have any URLs here to import the certificate Or I might say I don't have the need to. Moreover, I am not sure why this error is occurring on executing the java code given by the Twilio SendGrid official documentation
A little help on resolving this issue would be greatly appreciated, Thank You