Repository navigation
Description
Issue Summary
Use SendGrid api call and send the mail to api.sendgrid.com (port 443) . Some mails are failing and getting the following errors.
2016-12-21 00:08:02.250 [ERROR] [pool-3-thread-17] MailUtil - Email not sent
org.apache.http.NoHttpResponseException: api.sendgrid.com:443 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143) ~[httpclient-4.4.jar:4.4]
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57) ~[httpclient-4.4.jar:4.4]
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261) ~[httpcore-4.4.jar:4.4]
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165) ~[httpcore-4.4.jar:4.4]
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167) ~[httpclient-4.4.jar:4.4]
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272) ~[httpcore-4.4.jar:4.4]
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124) ~[httpcore-4.4.jar:4.4]
Steps to Reproduce
Email from = new Email (fromEmail, fromUserName);
Content content = new Content ("text/html", " "); //else it willthrough excepton that body shouldn't be empty
Mail email = new Mail ();
email.setFrom (from);
email.addContent (content);
Personalization personalization = new Personalization ();
email.addPersonalization (personalization);
email.setTemplateId(sendGridWelcomeTemplateId);
personalization.addSubstitution("-firstName-", fname );
personalization.addSubstitution("-lastName-", lname);
personalization.addTo( new Email ( email ));
Request request = new Request ();
request.method = Method.POST;
request.endpoint = "mail/send";
request.body = email.build ();
Response response = sendGrid.api (request);
log.info ("Got status code " + response.statusCode);
- Create the template in sendgrid
- Use the above code snippet and try to send mails with random intervals.
- After some time sending mail will get the above exception. But same mail will get dispatched if you reattempt to send mails .
Failed mails will get delivered after 2 or 3 attempts. It seems due to some reason the api server of sendgrid is getting the request and failed to respond back . once timeout happens the above exception thrown. I attached the mtr log for send grid.
sendgrid_mtr.txt
Technical details:
- Operating system: CentOS Linux 7 (3.10.0-229.14.1.el7.x86_64)
- sendgrid-java 3.1.0
- Java Version: 1.8
Activity
thinkingserious commentedon Jan 26, 2017
Hello @sureshthirumurugan,
It seems you might be running into a rate limiting problem. Check out this thread: sendgrid/sendgrid-php#173 (comment)
Please let me know what you find. Thanks!
gabber12 commentedon Nov 11, 2017
Facing a similar issue
This happens when resuing the same SendGrid.class instance for long.
My guess is the HttpClient connection is going stale and not handled properly.
Java 1.8
sendgrid-java 4.1
gabber12 commentedon Nov 13, 2017
This happens if the sendgrid client is reused for multiple api calls for a long time.
Fixed it by using a ClientPool with a small expiry.
mbernier commentedon Nov 13, 2017
@gabber12 Would you be interested in creating a PR against this repo with this change? I think this could be very helpful for other users of the library!!
MatteoGioioso commentedon May 6, 2019
same issue
thinkingserious commentedon Mar 11, 2021
Since there has been no activity on this issue since March 1, 2020, we are closing this issue. Please feel free to reopen or create a new issue if you still require assistance. Thank you!