use of jakarta.mail.util.ByteArrayDataSource in project resteasy by resteasy.
the class MimeMultipartProviderTest method testXop.
/**
* @tpTestDetails Custom jaxb object in put request with @XopWithMultipartRelated
* @tpSince RESTEasy 3.0.16
*/
@Test
public void testXop() throws Exception {
MimeMultipartProviderClient proxy = ProxyBuilder.builder(MimeMultipartProviderClient.class, client.target(generateURL(""))).build();
MimeMultipartProviderResource.Xop xop = new MimeMultipartProviderResource.Xop(new MimeMultipartProviderCustomer("bill\u00E9"), new MimeMultipartProviderCustomer("monica"), "Hello Xop World!".getBytes(StandardCharsets.UTF_8), new DataHandler(new ByteArrayDataSource("Hello Xop World!".getBytes(StandardCharsets.UTF_8), MediaType.APPLICATION_OCTET_STREAM)));
proxy.putXop(xop);
}
use of jakarta.mail.util.ByteArrayDataSource in project triplea by triplea-game.
the class DefaultEmailSender method sendEmail.
@Override
public void sendEmail(final String subject, final String htmlMessage, final Path saveGame, final String saveGameName) throws IOException {
// this is the last step and we create the email to send
final Properties props = new Properties();
props.put("mail.smtp.auth", "true");
if (encrypted) {
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
}
props.put("mail.smtp.host", emailServerHost);
props.put("mail.smtp.port", emailServerPort);
props.put("mail.smtp.connectiontimeout", TIMEOUT);
props.put("mail.smtp.timeout", TIMEOUT);
// todo get the turn and player number from the game data
try {
final Session session = Session.getInstance(props, null);
final MimeMessage mimeMessage = new MimeMessage(session);
// Build the message fields one by one:
// priority
mimeMessage.setHeader("X-Priority", "3 (Normal)");
// from
mimeMessage.setFrom(new InternetAddress(username));
// to address
for (final String token : Splitter.on(' ').omitEmptyStrings().trimResults().split(toAddress)) {
mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(token));
}
// subject
mimeMessage.setSubject(subjectPrefix + " " + subject);
final MimeBodyPart bodypart = new MimeBodyPart();
bodypart.setText(htmlMessage, "UTF-8");
bodypart.setHeader("Content-Type", "text/html");
if (saveGame != null) {
final Multipart multipart = new MimeMultipart();
multipart.addBodyPart(bodypart);
// add save game
try (InputStream fin = Files.newInputStream(saveGame)) {
final DataSource source = new ByteArrayDataSource(fin, "application/triplea");
final BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(saveGameName);
multipart.addBodyPart(messageBodyPart);
}
mimeMessage.setContent(multipart);
}
// date
try {
mimeMessage.setSentDate(Date.from(Instant.now()));
} catch (final Exception e) {
// NoOp - the Date field is simply ignored in this case
}
try (Transport transport = session.getTransport("smtp")) {
transport.connect(emailServerHost, emailServerPort, username, password);
mimeMessage.saveChanges();
transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
}
} catch (final MessagingException e) {
throw new IOException(e);
}
}
use of jakarta.mail.util.ByteArrayDataSource in project simple-java-mail by bbottema.
the class MimeMessageParserTest method testMoveInvalidEmbeddedResourcesToAttachments_Invalid.
@Test
public void testMoveInvalidEmbeddedResourcesToAttachments_Invalid() throws IOException {
ParsedMimeMessageComponents parsedComponents = new ParsedMimeMessageComponents();
parsedComponents.htmlContent.append("blah cid:moo1 blah html");
parsedComponents.cidMap.put("moo1", new ByteArrayDataSource("moomoo", "text/plain"));
parsedComponents.cidMap.put("moo2", new ByteArrayDataSource("moomoo", "text/plain"));
moveInvalidEmbeddedResourcesToAttachments(parsedComponents);
assertThat(parsedComponents.cidMap).containsOnlyKeys("moo1");
assertThat(parsedComponents.attachmentList).extracting("key").containsOnly("moo2");
}
use of jakarta.mail.util.ByteArrayDataSource in project simple-java-mail by bbottema.
the class EmailPopulatingBuilderImpl1Test method getDataSource.
@SuppressWarnings("SameParameterValue")
private ByteArrayDataSource getDataSource(@Nullable String name) throws IOException {
ByteArrayDataSource ds = new ByteArrayDataSource("", "text/text");
ds.setName(name);
return ds;
}
use of jakarta.mail.util.ByteArrayDataSource in project simple-java-mail by bbottema.
the class EmailPopulatingBuilderUsingDefaultsFromPropertyFileTest method testBuilderSimpleBuildWithStandardEmail.
@Test
public void testBuilderSimpleBuildWithStandardEmail() throws IOException {
ByteArrayDataSource namedAttachment = new ByteArrayDataSource("Black Tie Optional", "text/plain");
namedAttachment.setName("dresscode-ignored-because-of-override.txt");
String base64String = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABeElEQVRYw2NgoAAYGxu3GxkZ7TY1NZVloDcAWq4MxH+B+D8Qv3FwcOCgtwM6oJaDMTAUXOhmuYqKCjvQ0pdoDrCnmwNMTEwakC0H4u8GBgYC9Ap6DSD+iewAoIPm0ctyLqBlp9F8/x+YE4zpYT8T0LL16JYD8U26+B7oyz4sloPwenpYno3DchCeROsUbwa05A8eB3wB4kqgIxOAuArIng7EW4H4EhC/B+JXQLwDaI4ryZaDSjeg5mt4LCcFXyIn1fdSyXJQVt1OtMWGhoai0OD8T0W8GohZifE1PxD/o7LlsPLiFNAKRrwOABWptLAcqc6QGDAHQEOAYaAc8BNotsJAOgAUAosG1AFA/AtUoY3YEFhKMAvS2AE7iC1+WaG1H6gY3gzE36hUFJ8mqzbU1dUVBBqQBzTgIDQRkWo5qCZdpaenJ0Zx1aytrc0DDB0foIG1oAYKqC0IZK8D4n1AfA6IzwPxXpCFoGoZVEUDaRGGUTAKRgEeAAA2eGJC+ETCiAAAAABJRU5ErkJggg==";
fixLoadedPropertyPath(Property.SMIME_ENCRYPTION_CERTIFICATE);
final Email email = EmailBuilder.startingBlank().from("lollypop", "lol.pop@somemail.com").to("C.Cane", "candycane@candyshop.org").withPlainText("We should meet up!").withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>").withSubject("hey").withAttachment("dresscode.txt", namedAttachment).withAttachment("location.txt", "On the moon!".getBytes(Charset.defaultCharset()), "text/plain").withEmbeddedImage("thumbsup", parseBase64Binary(base64String), "image/png").buildEmail();
assertThat(EmailHelper.createDummyEmailBuilder(true, true, false, false, false, false).buildEmail()).isEqualTo(email);
}
Aggregations