本文整理汇总了Java中com.sendgrid.SendGridException类的典型用法代码示例。如果您正苦于以下问题:Java SendGridException类的具体用法?Java SendGridException怎么用?Java SendGridException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SendGridException类属于com.sendgrid包,在下文中一共展示了SendGridException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:kamax-io,项目名称:mxisd,代码行数:21,代码来源:EmailSendGridNotificationHandler.java
示例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"));
}
}
开发者ID:celestial-winter,项目名称:vics,代码行数:17,代码来源:SendGridClient.java
示例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()));
}
}
开发者ID:groupe-sii,项目名称:ogham,代码行数:22,代码来源:DelegateSendGridClient.java
示例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());
}
开发者ID:groupe-sii,项目名称:ogham,代码行数:24,代码来源:EmailSendGridTest.java
示例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());
}
开发者ID:groupe-sii,项目名称:ogham,代码行数:24,代码来源:EmailSendGridTest.java
示例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());
}
开发者ID:groupe-sii,项目名称:ogham,代码行数:24,代码来源:EmailSendGridTest.java
示例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());
}
开发者ID:groupe-sii,项目名称:ogham,代码行数:24,代码来源:EmailSendGridTest.java
示例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());
}
开发者ID:groupe-sii,项目名称:ogham,代码行数:24,代码来源:EmailSendGridTest.java
示例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.");
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:17,代码来源:SendEmailServlet.java
示例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;
}
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:21,代码来源:SendEmail.java
示例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;
}
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:20,代码来源:SendEmail.java
示例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;
}
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:23,代码来源:SendEmail.java
示例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());
}
}
开发者ID:Cryptonomica,项目名称:cryptonomica,代码行数:41,代码来源:SendGridServlet.java
示例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);
}
开发者ID:groupe-sii,项目名称:ogham,代码行数:12,代码来源:SendGridClientTest.java
示例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);
}
开发者ID:groupe-sii,项目名称:ogham,代码行数:10,代码来源:SendGridClientTest.java
示例16: service
import com.sendgrid.SendGridException; //导入依赖的package包/类
@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);
}
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:31,代码来源:SendEmailServlet.java
示例17: doInBackground
import com.sendgrid.SendGridException; //导入依赖的package包/类
@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;
}
开发者ID:danysantiago,项目名称:sendgrid-android,代码行数:33,代码来源:MainActivity.java
示例18: sendEmailWithService
import com.sendgrid.SendGridException; //导入依赖的package包/类
@Override
protected void sendEmailWithService(EmailWrapper wrapper) throws SendGridException {
Email email = parseToEmail(wrapper);
SendGrid sendgrid = new SendGrid(Config.SENDGRID_APIKEY);
Response response = sendgrid.send(email);
if (response.getCode() != SUCCESS_CODE) {
log.severe("Email failed to send: " + response.getMessage());
}
}
开发者ID:TEAMMATES,项目名称:teammates,代码行数:10,代码来源:SendgridService.java
示例19: sendConfirmationToPlayer
import com.sendgrid.SendGridException; //导入依赖的package包/类
private static void sendConfirmationToPlayer(Player player) {
SendGrid.Email sendGridEmail = new SendGrid.Email();
sendGridEmail.addTo(player.getEmail());
sendGridEmail.setFrom(CASH_EMAIL);
sendGridEmail.setSubject("You joined the tournament");
sendGridEmail.setText("You have just entered the 1vs1 tournament. " +
"To confirm your participation please donate the appropriate amount. You can find the donate link on playciv.com website. " +
"Afterwards please reply to this email and let me know that you have donated. Good luck and have fun!");
try {
sendgrid.send(sendGridEmail);
} catch (SendGridException e) {
log.error("Error sending sendGridEmail: " + e.getMessage(), e);
}
}
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:16,代码来源:SendEmail.java
示例20: sendUsingSendGrid
import com.sendgrid.SendGridException; //导入依赖的package包/类
public void sendUsingSendGrid(String from, String to, String subject, String msg) {
Email email = new Email();
email.setFrom(from);
email.addTo(to);
email.setSubject(subject);
email.setText(msg);
try {
sendGrid.send(email);
} catch (SendGridException e) {
logger.error(e.getMessage(), e);
}
}
开发者ID:AnujaK,项目名称:restfiddle,代码行数:14,代码来源:MailSender.java
注:本文中的com.sendgrid.SendGridException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论