use of com.sendgrid.SendGrid in project spring-boot by spring-projects.
the class SendGridAutoConfigurationTests method expectedSendGridBeanWithProxyCreated.
@Test
void expectedSendGridBeanWithProxyCreated() {
loadContext("spring.sendgrid.api-key:SG.SECRET-API-KEY", "spring.sendgrid.proxy.host:localhost", "spring.sendgrid.proxy.port:5678");
SendGrid sendGrid = this.context.getBean(SendGrid.class);
assertThat(sendGrid).extracting("client.httpClient.routePlanner").isInstanceOf(DefaultProxyRoutePlanner.class);
}
use of com.sendgrid.SendGrid in project OsmAnd-tools by osmandapp.
the class EmailSenderMain method main.
public static void main(String[] args) throws SQLException {
System.out.println("Send email utility");
EmailParams p = new EmailParams();
boolean updateBlockList = false;
for (String arg : args) {
String val = arg.substring(arg.indexOf("=") + 1);
if (arg.startsWith("--id=")) {
p.templateId = val;
} else if (arg.startsWith("--groups=")) {
p.mailingGroups = val;
} else if (arg.startsWith("--sender_mail=")) {
p.mailFrom = val;
} else if (arg.startsWith("--giveaway-series=")) {
p.giveawaySeries = val;
} else if (arg.startsWith("--subject=")) {
p.subject = val;
} else if (arg.startsWith("--topic=")) {
p.topic = val;
} else if (arg.startsWith("--run_opt=")) {
p.runMode = val;
} else if (arg.startsWith("--test_addr=")) {
p.testAddresses = val;
} else if (arg.startsWith("--since-days-ago=")) {
if (val.length() > 0) {
p.daySince = Integer.parseInt(val);
}
} else if (arg.equals("--update_block_list")) {
updateBlockList = true;
}
}
final String apiKey = System.getenv("SENDGRID_KEY");
sendGridClient = new SendGrid(apiKey);
Connection conn = getConnection();
if (updateBlockList) {
updateUnsubscribed(conn);
updateBlockList(conn);
conn.close();
return;
}
checkValidity(p);
if (conn == null) {
LOGGER.info("Can't connect to the database");
System.exit(1);
}
Set<String> unsubscribedAndBlocked = getUnsubscribedAndBlocked(conn, p.topic);
switch(p.runMode) {
case "send_to_test_email_group":
sendTestEmails(p, unsubscribedAndBlocked);
break;
case "print_statistics":
printStats(conn, p, unsubscribedAndBlocked);
break;
case "send_to_production":
sendProductionEmails(conn, p, unsubscribedAndBlocked);
break;
}
conn.close();
}
use of com.sendgrid.SendGrid in project cryptonomica by Cryptonomica.
the class SendGridServlet method doPost.
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// (?) ofy() should be used from HttpServletRequest context, not as static method in servlet class
final String SENDGRID_API_KEY = ofy().load().key(Key.create(AppSettings.class, "SendGridApiKey")).now().getValue();
/* --- get parameters */
String emailTO = req.getParameter("email");
String emailCC = req.getParameter("emailCC");
String messageSubject = req.getParameter("messageSubject");
String messageText = req.getParameter("messageText");
String type = req.getParameter("type");
/* --- log parameters */
LOG.warning("emailTO: " + emailTO);
LOG.warning("emailCC: " + emailCC);
LOG.warning("messageText: " + messageText);
LOG.warning("messageSubject: " + messageSubject);
/* initialize the SendGrid object with your SendGrid credentials */
SendGrid sendgrid = new SendGrid(SENDGRID_API_KEY);
/* create mail*/
SendGrid.Email email = new SendGrid.Email();
email.addTo(emailTO);
email.setFrom("admin@cryptonomica.net");
if (emailCC != null) {
email.addCc(emailCC);
}
email.setSubject(messageSubject);
email.setText(messageText);
try {
SendGrid.Response response = sendgrid.send(email);
LOG.warning(response.getMessage());
} catch (SendGridException e) {
LOG.warning(e.getMessage());
}
}
use of com.sendgrid.SendGrid in project CollectiveOneWebapp by CollectiveOne.
the class AppConfig method sendGrid.
@Bean
public SendGrid sendGrid() {
String key = System.getenv("SENDGRID_API_KEY");
SendGrid sg = new SendGrid(key);
sg.addRequestHeader("X-Mock", "true");
return sg;
}
use of com.sendgrid.SendGrid in project spring-boot by spring-projects.
the class SendGridAutoConfigurationTests method autoConfigurationNotFiredWhenBeanAlreadyCreated.
@Test
void autoConfigurationNotFiredWhenBeanAlreadyCreated() {
loadContext(ManualSendGridConfiguration.class, "spring.sendgrid.api-key:SG.SECRET-API-KEY");
SendGrid sendGrid = this.context.getBean(SendGrid.class);
assertThat(sendGrid.getRequestHeaders().get("Authorization")).isEqualTo("Bearer SG.CUSTOM_API_KEY");
}
Aggregations