本文整理汇总了Java中com.amazonaws.services.simpleemail.model.SendEmailRequest类的典型用法代码示例。如果您正苦于以下问题:Java SendEmailRequest类的具体用法?Java SendEmailRequest怎么用?Java SendEmailRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SendEmailRequest类属于com.amazonaws.services.simpleemail.model包,在下文中一共展示了SendEmailRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendEmail
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
/**
* Send email.
*
* @param eMsg the e msg
* @return true, if successful
*/
public boolean sendEmail(EmailMessage eMsg) {
SendEmailRequest request = new SendEmailRequest().withSource(eMsg.getFromAddress());
Destination dest = new Destination().withToAddresses(eMsg.getToAddresses());
dest.setCcAddresses(eMsg.getToCcAddresses());
request.setDestination(dest);
Content subjContent = new Content().withData(eMsg.getSubject());
Message msg = new Message().withSubject(subjContent);
Content textContent = new Content().withData(eMsg.getTxtMessage());
Body body = new Body().withText(textContent);
if (eMsg.getHtmlMessage() != null) {
Content htmlContent = new Content().withData(eMsg.getHtmlMessage());
body.setHtml(htmlContent);
}
msg.setBody(body);
request.setMessage(msg);
try {
emailClient.sendEmail(request);
logger.debug(msg);
} catch (AmazonClientException e) {
logger.error(e.getMessage());
return false;
}
return true;
}
示例2: send
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
public void send() throws IOException, TemplateException {
client = createClient();
Destination destination = new Destination().withToAddresses(new String[]{email});
Content subject = new Content().withData(SUBJECT);
String bodyContent = createBody();
Content textContent = new Content().withData(bodyContent);
Body body = new Body().withText(textContent);
Message message = new Message()
.withSubject(subject)
.withBody(body);
SendEmailRequest request = new SendEmailRequest()
.withSource(getSender())
.withDestination(destination)
.withMessage(message);
client.sendEmail(request);
}
示例3: sendEmails
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
public void sendEmails(List<String> emailAddresses,
String from,
String subject,
String emailBody) {
Message message = new Message()
.withSubject(new Content().withData(subject))
.withBody(new Body().withText(new Content().withData(emailBody)));
getChunkedEmailList(emailAddresses)
.forEach(group
-> client.sendEmail(new SendEmailRequest()
.withSource(from)
.withDestination(new Destination().withBccAddresses(group))
.withMessage(message))
);
shutdown();
}
示例4: sendEmail
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public EmailResponse sendEmail(EmailRequest emailRequest) {
try {
SendEmailResult result = this.asyncSES.sendEmail(new SendEmailRequest()
.withSource(this.emailConfig.from())
.withDestination(new Destination()
.withToAddresses(emailRequest.getRecipientToList())
.withCcAddresses(emailRequest.getRecipientCcList())
.withBccAddresses(emailRequest.getRecipientBccList()))
.withMessage(new Message()
.withSubject(new Content().withData(emailRequest.getSubject()))
.withBody(new Body().withHtml(new Content().withData(emailRequest.getBody())))));
return new EmailResponse(result.getMessageId(), result.getSdkHttpMetadata().getHttpStatusCode(),
result.getSdkHttpMetadata().getHttpHeaders());
} catch (Exception ex) {
LOGGER.error("Exception while sending email!!", ex);
throw new AwsException(ex.getMessage(), ex);
}
}
示例5: sendEmailAsync
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void sendEmailAsync(EmailRequest emailRequest) {
try {
// Shall we use the Future object returned by async call?
this.asyncSES.sendEmailAsync(new SendEmailRequest()
.withSource(this.emailConfig.from())
.withDestination(new Destination()
.withToAddresses(emailRequest.getRecipientToList())
.withCcAddresses(emailRequest.getRecipientCcList())
.withBccAddresses(emailRequest.getRecipientBccList()))
.withMessage(new Message()
.withSubject(new Content().withData(emailRequest.getSubject()))
.withBody(new Body().withHtml(new Content().withData(emailRequest.getBody())))),
this.asyncHandler);
} catch (Exception ex) {
LOGGER.error("Exception while sending email asynchronously!!", ex);
}
}
示例6: doInBackground
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
protected Void doInBackground(String...messages) {
if( messages.length == 0 ) return null;
// build the message and destination objects
Content subject = new Content( "OpenCaption" );
Body body = new Body( new Content( messages[0] ) );
Message message = new Message( subject, body );
Destination destination = new Destination().withToAddresses( toAddress );
// send out the email
SendEmailRequest request =
new SendEmailRequest( fromVerifiedAddress, destination, message );
// END:asynctask
SendEmailResult result =
// START:asynctask
sesClient.sendEmail( request );
// END:asynctask
Log.d( "glass.opencaption", "AWS SES resp message id:" + result.getMessageId() );
// START:asynctask
return null;
}
示例7: sendEmail
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
@Override
public boolean sendEmail(List<String> emails, String subject, String body) {
if (emails != null && !emails.isEmpty() && !StringUtils.isBlank(body)) {
final SendEmailRequest request = new SendEmailRequest().withSource(Config.SUPPORT_EMAIL);
Destination dest = new Destination().withToAddresses(emails);
request.setDestination(dest);
Content subjContent = new Content().withData(subject);
Message msg = new Message().withSubject(subjContent);
// Include a body in both text and HTML formats
Content textContent = new Content().withData(body).withCharset(Config.DEFAULT_ENCODING);
msg.setBody(new Body().withHtml(textContent));
request.setMessage(msg);
Para.asyncExecute(new Runnable() {
public void run() {
sesclient.sendEmail(request);
}
});
return true;
}
return false;
}
示例8: prepareMessage
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
private SendEmailRequest prepareMessage(SimpleMailMessage simpleMailMessage) {
Destination destination = new Destination();
destination.withToAddresses(simpleMailMessage.getTo());
if (simpleMailMessage.getCc() != null) {
destination.withCcAddresses(simpleMailMessage.getCc());
}
if (simpleMailMessage.getBcc() != null) {
destination.withBccAddresses(simpleMailMessage.getBcc());
}
Content subject = new Content(simpleMailMessage.getSubject());
Body body = new Body(new Content(simpleMailMessage.getText()));
SendEmailRequest emailRequest = new SendEmailRequest(simpleMailMessage.getFrom(), destination, new Message(subject, body));
if (StringUtils.hasText(simpleMailMessage.getReplyTo())) {
emailRequest.withReplyToAddresses(simpleMailMessage.getReplyTo());
}
return emailRequest;
}
示例9: testSendSimpleMailWithMinimalProperties
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
@Test
public void testSendSimpleMailWithMinimalProperties() throws Exception {
AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class);
SimpleEmailServiceMailSender mailSender = new SimpleEmailServiceMailSender(emailService);
SimpleMailMessage simpleMailMessage = createSimpleMailMessage();
ArgumentCaptor<SendEmailRequest> request = ArgumentCaptor.forClass(SendEmailRequest.class);
when(emailService.sendEmail(request.capture())).thenReturn(new SendEmailResult().withMessageId("123"));
mailSender.send(simpleMailMessage);
SendEmailRequest sendEmailRequest = request.getValue();
assertEquals(simpleMailMessage.getFrom(), sendEmailRequest.getSource());
assertEquals(simpleMailMessage.getTo()[0], sendEmailRequest.getDestination().getToAddresses().get(0));
assertEquals(simpleMailMessage.getSubject(), sendEmailRequest.getMessage().getSubject().getData());
assertEquals(simpleMailMessage.getText(), sendEmailRequest.getMessage().getBody().getText().getData());
assertEquals(0, sendEmailRequest.getDestination().getCcAddresses().size());
assertEquals(0, sendEmailRequest.getDestination().getBccAddresses().size());
}
示例10: testSendSimpleMailWithCCandBCC
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
@Test
public void testSendSimpleMailWithCCandBCC() throws Exception {
AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class);
SimpleEmailServiceMailSender mailSender = new SimpleEmailServiceMailSender(emailService);
SimpleMailMessage simpleMailMessage = createSimpleMailMessage();
simpleMailMessage.setBcc("[email protected]");
simpleMailMessage.setCc("[email protected]");
ArgumentCaptor<SendEmailRequest> request = ArgumentCaptor.forClass(SendEmailRequest.class);
when(emailService.sendEmail(request.capture())).thenReturn(new SendEmailResult().withMessageId("123"));
mailSender.send(simpleMailMessage);
SendEmailRequest sendEmailRequest = request.getValue();
assertEquals(simpleMailMessage.getFrom(), sendEmailRequest.getSource());
assertEquals(simpleMailMessage.getTo()[0], sendEmailRequest.getDestination().getToAddresses().get(0));
assertEquals(simpleMailMessage.getSubject(), sendEmailRequest.getMessage().getSubject().getData());
assertEquals(simpleMailMessage.getText(), sendEmailRequest.getMessage().getBody().getText().getData());
assertEquals(simpleMailMessage.getBcc()[0], sendEmailRequest.getDestination().getBccAddresses().get(0));
assertEquals(simpleMailMessage.getCc()[0], sendEmailRequest.getDestination().getCcAddresses().get(0));
}
示例11: testSendMultipleMailsWithExceptionWhileSending
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
@Test
public void testSendMultipleMailsWithExceptionWhileSending() throws Exception {
AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class);
SimpleEmailServiceMailSender mailSender = new SimpleEmailServiceMailSender(emailService);
SimpleMailMessage firstMessage = createSimpleMailMessage();
firstMessage.setBcc("[email protected]");
SimpleMailMessage failureMail = createSimpleMailMessage();
when(emailService.sendEmail(ArgumentMatchers.isA(SendEmailRequest.class))).
thenReturn(new SendEmailResult()).
thenThrow(new AmazonClientException("error")).
thenReturn(new SendEmailResult());
SimpleMailMessage thirdMessage = createSimpleMailMessage();
try {
mailSender.send(firstMessage, failureMail, thirdMessage);
fail("Exception expected due to error while sending mail");
} catch (MailSendException e) {
assertEquals(1, e.getFailedMessages().size());
assertTrue(e.getFailedMessages().containsKey(failureMail));
}
}
示例12: onSuccess
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
@Override
default void onSuccess(SendEmailRequest request, SendEmailResult result) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Email sent to: {}", request.getDestination().getToAddresses());
LOGGER.debug("SES SendEmailResult messageId: [{}]", result.getMessageId());
}
}
示例13: createMailRequest
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
private SendEmailRequest createMailRequest(Exchange exchange) {
SendEmailRequest request = new SendEmailRequest();
request.setSource(determineFrom(exchange));
request.setDestination(determineTo(exchange));
request.setReturnPath(determineReturnPath(exchange));
request.setReplyToAddresses(determineReplyToAddresses(exchange));
request.setMessage(createMessage(exchange));
return request;
}
示例14: sendEmail
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
@Override
public SendEmailResult sendEmail(SendEmailRequest sendEmailRequest) throws AmazonServiceException, AmazonClientException {
this.sendEmailRequest = sendEmailRequest;
SendEmailResult result = new SendEmailResult();
result.setMessageId("1");
return result;
}
示例15: emailVerification
import com.amazonaws.services.simpleemail.model.SendEmailRequest; //导入依赖的package包/类
public static void emailVerification(String name, String email, UUID uuid,
String username, String responseServletUrl, ServletConfig config) throws EmailUtilException {
String fromEmail = config.getServletContext().getInitParameter("return_email");
if (fromEmail == null || fromEmail.isEmpty()) {
logger.error("Missing return_email parameter in the web.xml file");
throw(new EmailUtilException("The from email for the email facility has not been set. Pleaese contact the OpenChain team with this error."));
}
String link = responseServletUrl + "?request=register&username=" + username + "&uuid=" + uuid.toString();
StringBuilder msg = new StringBuilder("<div>Welcome ");
msg.append(name);
msg.append(" to the OpenChain Certification website.<br /> <br />To complete your registration, click on the following or copy/paste into your web browser <a href=\"");
msg.append(link);
msg.append("\">");
msg.append(link);
msg.append("</a><br/><br/>Thanks,<br/>The OpenChain team</div>");
Destination destination = new Destination().withToAddresses(new String[]{email});
Content subject = new Content().withData("OpenChain Registration [do not reply]");
Content bodyData = new Content().withData(msg.toString());
Body body = new Body();
body.setHtml(bodyData);
Message message = new Message().withSubject(subject).withBody(body);
SendEmailRequest request = new SendEmailRequest().withSource(fromEmail).withDestination(destination).withMessage(message);
try {
AmazonSimpleEmailServiceClient client = getEmailClient(config);
client.sendEmail(request);
logger.info("Invitation email sent to "+email);
} catch (Exception ex) {
logger.error("Email send failed",ex);
throw(new EmailUtilException("Exception occured during the emailing of the invitation",ex));
}
}