当前位置: 首页>>代码示例>>Java>>正文


Java SendGrid类代码示例

本文整理汇总了Java中com.sendgrid.SendGrid的典型用法代码示例。如果您正苦于以下问题:Java SendGrid类的具体用法?Java SendGrid怎么用?Java SendGrid使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SendGrid类属于com.sendgrid包,在下文中一共展示了SendGrid类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setContent

import com.sendgrid.SendGrid; //导入依赖的package包/类
/**
 * Reads the content and adds it into the email. This method is expected to
 * update the content of the {@code email} parameter.
 * 
 * While the method signature accepts any {@link Content} instance as
 * parameter, the method will fail if anything other than a
 * {@link MultiContent} is provided.
 * 
 * @param email
 *            the email to put the content in
 * @param content
 *            the unprocessed content
 * @throws ContentHandlerException
 *             the handler is unable to add the content to the email
 * @throws IllegalArgumentException
 *             the content provided is not of the right type
 */
@Override
public void setContent(final SendGrid.Email email, final Content content) throws ContentHandlerException {
	if (email == null) {
		throw new IllegalArgumentException("[email] cannot be null");
	}
	if (content == null) {
		throw new IllegalArgumentException("[content] cannot be null");
	}

	if (content instanceof MultiContent) {
		for (Content subContent : ((MultiContent) content).getContents()) {
			delegate.setContent(email, subContent);
		}
	} else {
		throw new IllegalArgumentException("This instance can only work with MultiContent instances, but was passed " + content.getClass().getSimpleName());
	}
}
 
开发者ID:groupe-sii,项目名称:ogham,代码行数:35,代码来源:MultiContentHandler.java

示例2: send

import com.sendgrid.SendGrid; //导入依赖的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

示例3: toSendGridEmail

import com.sendgrid.SendGrid; //导入依赖的package包/类
private SendGrid.Email toSendGridEmail(final Email message) throws ContentHandlerException {
	final SendGrid.Email ret = new SendGrid.Email();
	ret.setSubject(message.getSubject());

	ret.setFrom(message.getFrom().getAddress());
	ret.setFromName(message.getFrom().getPersonal());

	final String[] tos = new String[message.getRecipients().size()];
	final String[] toNames = new String[message.getRecipients().size()];
	int i = 0;
	for (Recipient recipient : message.getRecipients()) {
		final EmailAddress address = recipient.getAddress();
		tos[i] = address.getAddress();
		toNames[i] = address.getPersonal();
		i++;
	}
	ret.setTo(tos);
	ret.setToName(toNames);

	handler.setContent(ret, message.getContent());

	return ret;
}
 
开发者ID:groupe-sii,项目名称:ogham,代码行数:24,代码来源:SendGridSender.java

示例4: forBasicTextEmail

import com.sendgrid.SendGrid; //导入依赖的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.SendGrid; //导入依赖的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.SendGrid; //导入依赖的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.SendGrid; //导入依赖的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.SendGrid; //导入依赖的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.SendGrid; //导入依赖的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.SendGrid; //导入依赖的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.SendGrid; //导入依赖的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.SendGrid; //导入依赖的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: baselineExample

import com.sendgrid.SendGrid; //导入依赖的package包/类
public static void baselineExample() throws IOException {
  SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
  sg.addRequestHeader("X-Mock", "true");

  Request request = new Request();
  Mail helloWorld = buildHelloEmail();
  try {
    request.setMethod(Method.POST);
    request.setEndpoint("mail/send");
    request.setBody(helloWorld.build());
    Response response = sg.api(request);
    System.out.println(response.getStatusCode());
    System.out.println(response.getBody());
    System.out.println(response.getHeaders());
  } catch (IOException ex) {
    throw ex;
  }
}
 
开发者ID:sendgrid,项目名称:sendgrid-java,代码行数:19,代码来源:Example.java

示例14: kitchenSinkExample

import com.sendgrid.SendGrid; //导入依赖的package包/类
public static void kitchenSinkExample() throws IOException {
  SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
  sg.addRequestHeader("X-Mock", "true");

  Request request = new Request();
  Mail kitchenSink = buildKitchenSink();
  try {
    request.setMethod(Method.POST);
    request.setEndpoint("mail/send");
    request.setBody(kitchenSink.build());
    Response response = sg.api(request);
    System.out.println(response.getStatusCode());
    System.out.println(response.getBody());
    System.out.println(response.getHeaders());
  } catch (IOException ex) {
    throw ex;
  }
}
 
开发者ID:sendgrid,项目名称:sendgrid-java,代码行数:19,代码来源:Example.java

示例15: main

import com.sendgrid.SendGrid; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
  try {
    SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
    Request request = new Request();
    request.setMethod(Method.GET);
    request.setEndpoint("mail_settings");
    request.addQueryParam("limit", "1");
    request.addQueryParam("offset", "1");
    Response response = sg.api(request);
    System.out.println(response.getStatusCode());
    System.out.println(response.getBody());
    System.out.println(response.getHeaders());
  } catch (IOException ex) {
    throw ex;
  }
}
 
开发者ID:sendgrid,项目名称:sendgrid-java,代码行数:17,代码来源:GetAllMailSettings.java


注:本文中的com.sendgrid.SendGrid类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。