sendgrid / sendgrid-java

The Official Twilio SendGrid Led, Community Driven Java API Library
https://sendgrid.com
MIT License
483 stars 408 forks source link

Unable to connect to sendgrid api via PCF #724

Closed rubenbasco closed 2 years ago

rubenbasco commented 2 years ago

Issue Summary

We are using the template code below to send email.

Code Snippet

            System.out.println("Sendgrid - building message");
            Email from = new Email(from);
            String subject = "Sending with SendGrid is Fun";
            Email to = new Email(recipient);
            Content content = new Content("text/plain", "Test content");
            Mail mail = new Mail(from, subject, to, content);

            SendGrid sg = new 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("Sendgrid - " + response.getStatusCode());
            System.out.println("Sendgrid - " + response.getBody());
            System.out.println("Sendgrid - " + response.getHeaders());

This works in my local, but when deployed in PCF I get this error

Exception/Log

2022-03-21T21:40:51.388+08:00 [APP/PROC/WEB/0] [ERR] org.apache.http.conn.HttpHostConnectException: Connect to api.sendgrid.com:443 [api.sendgrid.com/167.89.123.62, api.sendgrid.com/52.203.156.195, api.sendgrid.com/167.89.123.121, api.sendgrid.com/54.90.121.51, api.sendgrid.com/167.89.115.9, api.sendgrid.com/54.163.95.120, api.sendgrid.com/167.89.115.104, api.sendgrid.com/167.89.123.56, api.sendgrid.com/167.89.115.83, api.sendgrid.com/54.90.52.143, api.sendgrid.com/52.205.106.236, api.sendgrid.com/167.89.115.105, api.sendgrid.com/3.82.73.119, api.sendgrid.com/167.89.123.111, api.sendgrid.com/167.89.115.21, api.sendgrid.com/167.89.123.86] failed: Connection timed out (Connection timed out)

Is there some sort of configuration needed to be done on the Sendgrid account to allow PCF to send email (vice versa)?

beebzz commented 2 years ago

Hi @rubenbasco, thanks for opening an issue. This doesn't seem like a library-specific issue or error, so we encourage you to contact SendGrid Customer Support.