use of org.simplejavamail.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class MailTestDemoApp method main.
public static void main(final String[] args) throws Exception {
final EmailPopulatingBuilder emailPopulatingBuilderNormal = EmailBuilder.startingBlank();
emailPopulatingBuilderNormal.from("lollypop", "lol.pop@somemail.com");
// don't forget to add your own address here ->
emailPopulatingBuilderNormal.to("C.Cane", YOUR_GMAIL_ADDRESS);
emailPopulatingBuilderNormal.withPlainText("We should meet up!");
emailPopulatingBuilderNormal.withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>");
emailPopulatingBuilderNormal.withSubject("hey");
// add two text files in different ways and a black thumbs up embedded image ->
emailPopulatingBuilderNormal.withAttachment("dresscode.txt", new ByteArrayDataSource("Black Tie Optional", "text/plain"));
emailPopulatingBuilderNormal.withAttachment("location.txt", "On the moon!".getBytes(Charset.defaultCharset()), "text/plain");
String base64String = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABeElEQVRYw2NgoAAYGxu3GxkZ7TY1NZVloDcAWq4MxH+B+D8Qv3FwcOCgtwM6oJaDMTAUXOhmuYqKCjvQ0pdoDrCnmwNMTEwakC0H4u8GBgYC9Ap6DSD+iewAoIPm0ctyLqBlp9F8/x+YE4zpYT8T0LL16JYD8U26+B7oyz4sloPwenpYno3DchCeROsUbwa05A8eB3wB4kqgIxOAuArIng7EW4H4EhC/B+JXQLwDaI4ryZaDSjeg5mt4LCcFXyIn1fdSyXJQVt1OtMWGhoai0OD8T0W8GohZifE1PxD/o7LlsPLiFNAKRrwOABWptLAcqc6QGDAHQEOAYaAc8BNotsJAOgAUAosG1AFA/AtUoY3YEFhKMAvS2AE7iC1+WaG1H6gY3gzE36hUFJ8mqzbU1dUVBBqQBzTgIDQRkWo5qCZdpaenJ0Zx1aytrc0DDB0foIG1oAYKqC0IZK8D4n1AfA6IzwPxXpCFoGoZVEUDaRGGUTAKRgEeAAA2eGJC+ETCiAAAAABJRU5ErkJggg==";
emailPopulatingBuilderNormal.withEmbeddedImage("thumbsup", parseBase64Binary(base64String), "image/png");
// let's try producing and then consuming a MimeMessage ->
Email emailNormal = emailPopulatingBuilderNormal.buildEmail();
final MimeMessage mimeMessage = EmailConverter.emailToMimeMessage(emailNormal);
final Email emailFromMimeMessage = EmailConverter.mimeMessageToEmail(mimeMessage);
// note: the following statements will produce 6 new emails!
sendMail(emailNormal);
// should produce the exact same result as emailPopulatingBuilderNormal!
sendMail(emailFromMimeMessage);
}
use of org.simplejavamail.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class MailerTest method testDKIMPriming.
@Test
public void testDKIMPriming() throws IOException, MessagingException {
final EmailPopulatingBuilder emailPopulatingBuilder = EmailHelper.createDummyEmailBuilder(true, false, false);
// System.out.println(printBase64Binary(Files.readAllBytes(Paths.get("D:\\keys\\dkim.der")))); // needs jdk 1.7
String privateDERkeyBase64 = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMYuC7ZjFBSWJtP6JH8w1deJE+5sLwkUacZcW4MTVQXTM33BzN8Ec64KO1Hk2B9oxkpdunKt" + "BggwbWMlGU5gGu4PpQ20cdPcfBIkUMlQKaakHPPGNYaF9dQaZIRy8XON6g1sOJGALXtUYX1r5hdDH13kC/YBw9f1Dsi2smrB0qabAgMBAAECgYAdWbBuYJoWum4hssg49hiVhT2ob+k" + "/ZQCNWhxLe096P18+3rbiyJwBSI6kgEnpzPChDuSQG0PrbpCkwFfRHbafDIPiMi5b6YZkJoFmmOmBHsewS1VdR/phk+aPQV2SoJ0S0FAGZkOnOkagHfmEMSgjZzTpJouu5NU8mwqz8z" + "/s0QJBAOUnELTMG/Se3Pw4FQ49K49lA81QaMoL63lYIEvc6uSVoJSEcrBFxv5sfJW2LFWs8VIDyTvYzsCjLwZj6nwA3k0CQQDdZgVHX7crlpUxO/cjKtTa/Nq9S6XLv3S6XX3YJJ9/Z" + "pYpqAWJbbR+8scBgVxS+9NLLeHhlx/EvkaZRdLhwRyHAkEAtr1ThkqrFIXHxt9Wczd20HCG+qlgF5gv3WHYx4bSTx2/pBCHgWjzyxtqst1HN7+l5nicdrxsDJVVv+vYJ7FtlQJAWPgG" + "Zwgvs3Rvv7k5NwifQOEbhbZAigAGCF5Jk/Ijpi6zaUn7754GSn2FOzWgxDguUKe/fcgdHBLai/1jIRVZQQJAXF2xzWMwP+TmX44QxK52QHVI8mhNzcnH7A311gWns6AbLcuLA9quwjU" + "YJMRlfXk67lJXCleZL15EpVPrQ34KlA==";
emailPopulatingBuilder.signWithDomainKey(new ByteArrayInputStream(parseBase64Binary(privateDERkeyBase64)), "somemail.com", "select");
MimeMessage mimeMessage = EmailConverter.emailToMimeMessage(emailPopulatingBuilder.buildEmail());
// success, signing did not produce an error
assertThat(mimeMessage).isInstanceOf(DkimMessage.class);
}
use of org.simplejavamail.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class MailerTest method testParser.
@Test
public void testParser() throws Exception {
final EmailPopulatingBuilder emailPopulatingBuilderNormal = EmailHelper.createDummyEmailBuilder(true, false, false);
// let's try producing and then consuming a MimeMessage ->
// (bounce recipient is not part of the Mimemessage, but the Envelope and is configured on the Session, so just ignore this)
emailPopulatingBuilderNormal.clearBounceTo();
Email emailNormal = emailPopulatingBuilderNormal.buildEmail();
final MimeMessage mimeMessage = EmailConverter.emailToMimeMessage(emailNormal);
final Email emailFromMimeMessage = EmailConverter.mimeMessageToEmail(mimeMessage);
assertThat(emailFromMimeMessage).isEqualTo(emailNormal);
}
use of org.simplejavamail.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class EmailConverter method outlookMsgToEmail.
/**
* @param msgData The content of an Outlook (.msg) message from which to create the {@link Email}.
*/
public static Email outlookMsgToEmail(@Nonnull final String msgData) {
final EmailPopulatingBuilder emailPopulatingBuilder = EmailBuilder.ignoringDefaults().startingBlank();
final OutlookMessage outlookMessage = OutlookMessageParser.parseOutlookMsg(checkNonEmptyArgument(msgData, "msgData"));
buildEmailFromOutlookMessage(emailPopulatingBuilder, outlookMessage);
return emailPopulatingBuilder.buildEmail();
}
use of org.simplejavamail.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class EmailConverter method mimeMessageToEmailBuilder.
/**
* @param mimeMessage The MimeMessage from which to create the {@link Email}.
*/
public static EmailPopulatingBuilder mimeMessageToEmailBuilder(@Nonnull final MimeMessage mimeMessage) {
checkNonEmptyArgument(mimeMessage, "mimeMessage");
final EmailPopulatingBuilder emailPopulatingBuilder = EmailBuilder.ignoringDefaults().startingBlank();
buildEmailFromMimeMessage(emailPopulatingBuilder, MimeMessageParser.parseMimeMessage(mimeMessage));
return emailPopulatingBuilder;
}
Aggregations