use of com.sendgrid.SendGrid in project spring-boot by spring-projects.
the class SendGridAutoConfigurationTests method expectedSendGridBeanCreatedUsername.
@Test
public void expectedSendGridBeanCreatedUsername() {
loadContext("spring.sendgrid.username:user", "spring.sendgrid.password:secret");
SendGrid sendGrid = this.context.getBean(SendGrid.class);
assertThat(sendGrid).extracting("username").containsExactly("user");
assertThat(sendGrid).extracting("password").containsExactly("secret");
}
use of com.sendgrid.SendGrid in project spring-boot by spring-projects.
the class SendGridAutoConfiguration method sendGrid.
@Bean
@ConditionalOnMissingBean(SendGrid.class)
public SendGrid sendGrid() {
SendGrid sendGrid = createSendGrid();
if (this.properties.isProxyConfigured()) {
HttpHost proxy = new HttpHost(this.properties.getProxy().getHost(), this.properties.getProxy().getPort());
sendGrid.setClient(HttpClientBuilder.create().setProxy(proxy).setUserAgent("sendgrid/" + sendGrid.getVersion() + ";java").build());
}
return sendGrid;
}
use of com.sendgrid.SendGrid in project java-docs-samples by GoogleCloudPlatform.
the class SendEmailServlet method main.
public static void main(String[] args) throws SendGridException {
SendGrid sendgrid = new SendGrid(SENDGRID_API_KEY);
SendGrid.Email email = new SendGrid.Email();
email.addTo(TO_EMAIL);
email.setFrom(SENDGRID_SENDER);
email.setSubject("This is a test email");
email.setText("Example text body.");
SendGrid.Response response = sendgrid.send(email);
if (response.getCode() != 200) {
System.out.print(String.format("An error occured: %s", response.getMessage()));
return;
}
System.out.print("Email sent.");
}
use of com.sendgrid.SendGrid in project java-docs-samples by GoogleCloudPlatform.
the class SendEmailServlet method service.
@Override
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
final String sendgridApiKey = System.getenv("SENDGRID_API_KEY");
final String sendgridSender = System.getenv("SENDGRID_SENDER");
final String toEmail = req.getParameter("to");
if (toEmail == null) {
resp.getWriter().print("Please provide an email address in the \"to\" query string parameter.");
return;
}
SendGrid sendgrid = new SendGrid(sendgridApiKey);
SendGrid.Email email = new SendGrid.Email();
email.addTo(toEmail);
email.setFrom(sendgridSender);
email.setSubject("This is a test email");
email.setText("Example text body.");
try {
SendGrid.Response response = sendgrid.send(email);
if (response.getCode() != 200) {
resp.getWriter().print(String.format("An error occured: %s", response.getMessage()));
return;
}
resp.getWriter().print("Email sent.");
} catch (SendGridException e) {
throw new ServletException("SendGrid error", e);
}
}
use of com.sendgrid.SendGrid in project java-docs-samples by GoogleCloudPlatform.
the class SendEmailServlet method service.
@Override
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
final String sendgridApiKey = System.getenv("SENDGRID_API_KEY");
final String sendgridSender = System.getenv("SENDGRID_SENDER");
final String toEmail = req.getParameter("to");
if (toEmail == null) {
resp.getWriter().print("Please provide an email address in the \"to\" query string parameter.");
return;
}
SendGrid sendgrid = new SendGrid(sendgridApiKey);
SendGrid.Email email = new SendGrid.Email();
email.addTo(toEmail);
email.setFrom(sendgridSender);
email.setSubject("This is a test email");
email.setText("Example text body.");
try {
SendGrid.Response response = sendgrid.send(email);
if (response.getCode() != 200) {
resp.getWriter().print(String.format("An error occured: %s", response.getMessage()));
return;
}
resp.getWriter().print("Email sent.");
} catch (SendGridException e) {
throw new ServletException("SendGrid error", e);
}
}
Aggregations