本文整理汇总了Java中com.sendgrid.SendGridException类的典型用法代码示例。如果您正苦于以下问题:Java SendGridException类的具体用法?Java SendGridException怎么用?Java SendGridException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SendGridException类属于com.sendgrid包,在下文中一共展示了SendGridException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import com.sendgrid.SendGridException; //导入依赖的package包/类
private void send(String recipient, Email email) {
if (StringUtils.isBlank(cfg.getIdentity().getFrom())) {
throw new FeatureNotAvailable("3PID Email identity: sender address is empty - " +
"You must set a value for notifications to work");
}
try {
email.addTo(recipient);
email.setFrom(cfg.getIdentity().getFrom());
email.setFromName(cfg.getIdentity().getName());
Response response = sendgrid.send(email);
if (response.getStatus()) {
log.info("Successfully sent email to {} using SendGrid", recipient);
} else {
throw new RuntimeException("Error sending via SendGrid to " + recipient + ": " + response.getMessage());
}
} catch (SendGridException e) {
throw new RuntimeException("Unable to send e-mail invite via SendGrid to " + recipient, e);
}
}
示例2: sendEmail
import com.sendgrid.SendGridException; //导入依赖的package包/类
private Try<EmailResponse> sendEmail(Email email) {
String recipients = Arrays.toString(email.getTos());
try {
Response response = sendGrid.send(email);
if (!response.getStatus()) {
log.info(String.format("Failed to send password reset notification to %s (using SendGrid). %s", recipients, response.getMessage()));
return failure(new PasswordNotificationFailure("Failed to send password to username " + recipients));
} else {
log.info(String.format("Sent email to %s", recipients));
return success(ImmutableEmailResponse.builder().withMessage(response.getMessage()).build());
}
} catch (SendGridException e) {
log.error(String.format("Failed to contact SendGrid to send password reset notification. Recipients=%s", recipients), e);
return failure(new SendGridApiFailure("Failed to send password"));
}
}
示例3: send
import com.sendgrid.SendGridException; //导入依赖的package包/类
@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());
initSendGridClient();
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()));
}
}
示例4: forBasicTextEmail
import com.sendgrid.SendGridException; //导入依赖的package包/类
@Test
public void forBasicTextEmail() throws MessagingException, SendGridException {
// @formatter:off
final Email email = new Email()
.subject(SUBJECT)
.content(CONTENT_TEXT)
.from(new EmailAddress(FROM_ADDRESS, FROM))
.to(new EmailAddress(TO_ADDRESS_1, TO));
// @formatter:on
messagingService.send(email);
final ArgumentCaptor<SendGrid.Email> argument = ArgumentCaptor.forClass(SendGrid.Email.class);
verify(sendGridClient).send(argument.capture());
final SendGrid.Email val = argument.getValue();
assertEquals(SUBJECT, val.getSubject());
assertEquals(FROM, val.getFromName());
assertEquals(FROM_ADDRESS, val.getFrom());
assertEquals(TO, val.getToNames()[0]);
assertEquals(TO_ADDRESS_1, val.getTos()[0]);
assertEquals(CONTENT_TEXT, val.getText());
}
示例5: forAccentedTextEmail
import com.sendgrid.SendGridException; //导入依赖的package包/类
@Test
public void forAccentedTextEmail() throws MessagingException, SendGridException {
// @formatter:off
final Email email = new Email()
.subject(SUBJECT)
.content(new StringContent(CONTENT_TEXT_ACCENTED))
.from(new EmailAddress(FROM_ADDRESS, FROM))
.to(new EmailAddress(TO_ADDRESS_1, TO));
// @formatter:on
messagingService.send(email);
final ArgumentCaptor<SendGrid.Email> argument = ArgumentCaptor.forClass(SendGrid.Email.class);
verify(sendGridClient).send(argument.capture());
final SendGrid.Email val = argument.getValue();
assertEquals(SUBJECT, val.getSubject());
assertEquals(FROM, val.getFromName());
assertEquals(FROM_ADDRESS, val.getFrom());
assertEquals(TO, val.getToNames()[0]);
assertEquals(TO_ADDRESS_1, val.getTos()[0]);
assertEquals(CONTENT_TEXT_ACCENTED, val.getText());
}
示例6: forBasicHtmlEmail
import com.sendgrid.SendGridException; //导入依赖的package包/类
@Test
public void forBasicHtmlEmail() throws MessagingException, SendGridException {
// @formatter:off
final Email email = new Email()
.subject(SUBJECT)
.content(new StringContent(CONTENT_HTML))
.from(new EmailAddress(FROM_ADDRESS, FROM))
.to(new EmailAddress(TO_ADDRESS_1, TO));
// @formatter:on
messagingService.send(email);
final ArgumentCaptor<SendGrid.Email> argument = ArgumentCaptor.forClass(SendGrid.Email.class);
verify(sendGridClient).send(argument.capture());
final SendGrid.Email val = argument.getValue();
assertEquals(SUBJECT, val.getSubject());
assertEquals(FROM, val.getFromName());
assertEquals(FROM_ADDRESS, val.getFrom());
assertEquals(TO, val.getToNames()[0]);
assertEquals(TO_ADDRESS_1, val.getTos()[0]);
assertEquals(CONTENT_HTML, val.getHtml());
}
示例7: forTemplatedTextEmail
import com.sendgrid.SendGridException; //导入依赖的package包/类
@Test
public void forTemplatedTextEmail() throws MessagingException, SendGridException {
// @formatter:off
final Email email = new Email()
.subject(SUBJECT)
.content(new TemplateContent("string:" + CONTENT_TEXT_TEMPLATE, new SimpleContext("name", NAME)))
.from(new EmailAddress(FROM_ADDRESS, FROM))
.to(new EmailAddress(TO_ADDRESS_1, TO), new EmailAddress(TO_ADDRESS_2, TO));
// @formatter:on
messagingService.send(email);
final ArgumentCaptor<SendGrid.Email> argument = ArgumentCaptor.forClass(SendGrid.Email.class);
verify(sendGridClient).send(argument.capture());
final SendGrid.Email val = argument.getValue();
assertEquals(SUBJECT, val.getSubject());
assertEquals(FROM, val.getFromName());
assertEquals(FROM_ADDRESS, val.getFrom());
assertArrayEquals(new String[] { TO, TO }, val.getToNames());
assertArrayEquals(new String[] { TO_ADDRESS_1, TO_ADDRESS_2 }, val.getTos());
assertEquals(CONTENT_TEXT_RESULT, val.getText());
}
示例8: forTemplatedHtmlEmail
import com.sendgrid.SendGridException; //导入依赖的package包/类
@Test
public void forTemplatedHtmlEmail() throws MessagingException, SendGridException {
// @formatter:off
final Email email = new Email()
.subject(SUBJECT)
.content(new TemplateContent("string:" + CONTENT_HTML_TEMPLATE, new SimpleContext("name", NAME)))
.from(new EmailAddress(FROM_ADDRESS, FROM))
.to(new EmailAddress(TO_ADDRESS_1, TO), new EmailAddress(TO_ADDRESS_2, TO));
// @formatter:on
messagingService.send(email);
final ArgumentCaptor<SendGrid.Email> argument = ArgumentCaptor.forClass(SendGrid.Email.class);
verify(sendGridClient).send(argument.capture());
final SendGrid.Email val = argument.getValue();
assertEquals(SUBJECT, val.getSubject());
assertEquals(FROM, val.getFromName());
assertEquals(FROM_ADDRESS, val.getFrom());
assertArrayEquals(new String[] { TO, TO }, val.getToNames());
assertArrayEquals(new String[] { TO_ADDRESS_1, TO_ADDRESS_2 }, val.getTos());
assertEquals(CONTENT_HTML_RESULT, val.getHtml());
}
示例9: main
import com.sendgrid.SendGridException; //导入依赖的package包/类
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.");
}
示例10: sendYourTurn
import com.sendgrid.SendGridException; //导入依赖的package包/类
public static boolean sendYourTurn(String gamename, String emailToo, String pbfId) {
if (System.getenv(SENDGRID_USERNAME) == null || System.getenv(SENDGRID_PASSWORD) == null) {
log.error("Missing environment variable for SENDGRID_USERNAME or SENDGRID_PASSWORD");
return false;
}
SendGrid.Email email = new SendGrid.Email();
email.addTo(emailToo);
email.setFrom(NOREPLY_PLAYCIV_COM);
email.setSubject("It is your turn");
email.setText("It's your turn to play in " + gamename + "!\n\n" +
"Go to " + gamelink(pbfId) + " to start your turn");
try {
SendGrid.Response response = sendgrid.send(email);
return response.getStatus();
} catch (SendGridException e) {
log.error("Error sending email: " + e.getMessage(), e);
}
return false;
}
示例11: sendMessage
import com.sendgrid.SendGridException; //导入依赖的package包/类
public static boolean sendMessage(String email, String subject, String message, String playerId) {
if (System.getenv(SENDGRID_USERNAME) == null || System.getenv(SENDGRID_PASSWORD) == null) {
log.error("Missing environment variable for SENDGRID_USERNAME or SENDGRID_PASSWORD");
return false;
}
SendGrid.Email sendGridEmail = new SendGrid.Email();
sendGridEmail.addTo(email);
sendGridEmail.setFrom(NOREPLY_PLAYCIV_COM);
sendGridEmail.setSubject(subject);
sendGridEmail.setText(message + UNSUBSCRIBE(playerId));
try {
SendGrid.Response response = sendgrid.send(sendGridEmail);
return response.getStatus();
} catch (SendGridException e) {
log.error("Error sending sendGridEmail: " + e.getMessage(), e);
}
return false;
}
示例12: someoneJoinedTournament
import com.sendgrid.SendGridException; //导入依赖的package包/类
public static boolean someoneJoinedTournament(Player player) {
if (System.getenv(SENDGRID_USERNAME) == null || System.getenv(SENDGRID_PASSWORD) == null) {
log.error("Missing environment variable for SENDGRID_USERNAME or SENDGRID_PASSWORD");
return false;
}
SendGrid.Email sendGridEmail = new SendGrid.Email();
sendGridEmail.addTo(CASH_EMAIL);
sendGridEmail.setFrom(NOREPLY_PLAYCIV_COM);
sendGridEmail.setSubject(player.getUsername() + " joined tournament");
sendGridEmail.setText(player.getUsername() + " with email " + player.getEmail() + " joined the tournament");
try {
SendGrid.Response response = sendgrid.send(sendGridEmail);
sendConfirmationToPlayer(player);
return response.getStatus();
} catch (SendGridException e) {
log.error("Error sending sendGridEmail: " + e.getMessage(), e);
}
return false;
}
示例13: doPost
import com.sendgrid.SendGridException; //导入依赖的package包/类
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("[email protected]");
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());
}
}
示例14: send
import com.sendgrid.SendGridException; //导入依赖的package包/类
@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);
}
示例15: send_errorResponse
import com.sendgrid.SendGridException; //导入依赖的package包/类
@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);
}