Search in sources :

Example 11 with SendGrid

use of com.sendgrid.SendGrid in project spring-boot by spring-projects.

the class SendGridAutoConfigurationTests method expectedSendGridBeanCreatedApiKey.

@Test
void expectedSendGridBeanCreatedApiKey() {
    loadContext("spring.sendgrid.api-key:SG.SECRET-API-KEY");
    SendGrid sendGrid = this.context.getBean(SendGrid.class);
    assertThat(sendGrid.getRequestHeaders().get("Authorization")).isEqualTo("Bearer SG.SECRET-API-KEY");
}
Also used : SendGrid(com.sendgrid.SendGrid) Test(org.junit.jupiter.api.Test)

Example 12 with SendGrid

use of com.sendgrid.SendGrid in project iaf by ibissource.

the class SendGridSender method open.

@Override
public void open() throws SenderException {
    super.open();
    httpSender.open();
    CloseableHttpClient httpClient = httpSender.getHttpClient();
    if (httpClient == null)
        throw new SenderException("no HttpClient found, did it initialize properly?");
    Client client = new Client(httpClient);
    sendGrid = new SendGrid(getCredentialFactory().getPassword(), client);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) SendGrid(com.sendgrid.SendGrid) SenderException(nl.nn.adapterframework.core.SenderException) Client(com.sendgrid.Client) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient)

Example 13 with SendGrid

use of com.sendgrid.SendGrid in project teammates by TEAMMATES.

the class SendgridService method sendEmailWithService.

@Override
protected void sendEmailWithService(EmailWrapper wrapper) throws IOException {
    Mail email = parseToEmail(wrapper);
    SendGrid sendgrid = new SendGrid(Config.SENDGRID_APIKEY);
    Request request = new Request();
    request.setMethod(Method.POST);
    request.setEndpoint("mail/send");
    request.setBody(email.build());
    Response response = sendgrid.api(request);
    if (isNotSuccessStatus(response.getStatusCode())) {
        log.severe("Email failed to send: " + response.getBody());
    }
}
Also used : Response(com.sendgrid.Response) SendGrid(com.sendgrid.SendGrid) Mail(com.sendgrid.Mail) Request(com.sendgrid.Request)

Aggregations

SendGrid (com.sendgrid.SendGrid)13 SendGridException (com.sendgrid.SendGridException)3 Test (org.junit.jupiter.api.Test)3 ServletException (javax.servlet.ServletException)2 Bean (org.springframework.context.annotation.Bean)2 Client (com.sendgrid.Client)1 Mail (com.sendgrid.Mail)1 Request (com.sendgrid.Request)1 Response (com.sendgrid.Response)1 Connection (java.sql.Connection)1 AppSettings (net.cryptonomica.entities.AppSettings)1 SenderException (nl.nn.adapterframework.core.SenderException)1 HttpHost (org.apache.http.HttpHost)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 Test (org.junit.Test)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1