Java Code Examples for com.sendgrid.SendGrid#Response
The following examples show how to use
com.sendgrid.SendGrid#Response .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DelegateSendGridClient.java From ogham with Apache License 2.0 | 6 votes |
@Override public void send(final Email email) throws SendGridException { if (email == null) { throw new IllegalArgumentException("[email] cannot be null"); } LOG.debug("Sending to SendGrid client: FROM {}<{}>", email.getFromName(), email.getFrom()); LOG.debug("Sending to SendGrid client: TO {} (as {})", email.getTos(), email.getToNames()); LOG.debug("Sending to SendGrid client: SUBJECT {}", email.getSubject()); LOG.debug("Sending to SendGrid client: TEXT CONTENT {}", email.getText()); LOG.debug("Sending to SendGrid client: HTML CONTENT {}", email.getHtml()); final SendGrid.Response response = delegate.send(email); if (response.getStatus()) { LOG.debug("Response from SendGrid client: ({}) {}", response.getCode(), response.getMessage()); } else { throw new SendGridException(new IOException("Sending to SendGrid failed: (" + response.getCode() + ") " + response.getMessage())); } }
Example 2
Source File: SendGridClientTest.java From ogham with Apache License 2.0 | 5 votes |
@Test public void send() throws SendGridException { final SendGrid.Response response = new SendGrid.Response(200, "OK"); final SendGrid.Email exp = new SendGrid.Email(); when(delegate.send(exp)).thenReturn(response); instance.send(exp); verify(delegate).send(exp); }
Example 3
Source File: SendGridClientTest.java From ogham with Apache License 2.0 | 5 votes |
@Test(expected = SendGridException.class) public void send_errorResponse() throws SendGridException { final SendGrid.Response response = new SendGrid.Response(403, "FORBIDDEN"); final SendGrid.Email exp = new SendGrid.Email(); when(delegate.send(exp)).thenReturn(response); instance.send(exp); }
Example 4
Source File: MainActivity.java From sendgrid-android with MIT License | 5 votes |
@Override protected Void doInBackground(Void... params) { try { SendGrid sendgrid = new SendGrid(SENDGRID_USERNAME, SENDGRID_PASSWORD); SendGrid.Email email = new SendGrid.Email(); // Get values from edit text to compose email // TODO: Validate edit texts email.addTo(mTo); email.setFrom(mFrom); email.setSubject(mSubject); email.setText(mText); // Attach image if (mUri != null) { email.addAttachment(mAttachmentName, mAppContext.getContentResolver().openInputStream(mUri)); } // Send email, execute http request SendGrid.Response response = sendgrid.send(email); mMsgResponse = response.getMessage(); Log.d("SendAppExample", mMsgResponse); } catch (SendGridException | IOException e) { Log.e("SendAppExample", e.toString()); } return null; }
Example 5
Source File: SendGridEmailService.java From dropwizard-experiment with MIT License | 5 votes |
@Override public void send(String toAddress, String subject, String htmlContent) { SendGrid.Email email = new SendGrid.Email(); email.setSubject(subject); email.setHtml(htmlContent); email.setFrom(config.getFromEmail()); email.setFromName(config.getFromName()); if (!Strings.isNullOrEmpty(config.getOverrideReceiver())) { email.addTo(config.getOverrideReceiver()); } else { email.addTo(toAddress); } try { SendGrid.Response response = sendGrid.send(email); if (!response.getStatus()) { metrics.meter(MetricRegistry.name("email", "send", "failure", toMetricName(toAddress))).mark(); log.error("Error sending email via SendGrid:", response.getMessage()); } else { metrics.meter(MetricRegistry.name("email", "send", "success", toMetricName(toAddress))).mark(); } } catch (SendGridException e) { metrics.meter(MetricRegistry.name("email", "send", "failure", toMetricName(toAddress))).mark(); log.error("Error sending email via SendGrid:", e); } }