use of javax.mail.internet.MimeMessage in project spring-framework by spring-projects.
the class JavaMailSenderTests method testJavaMailSenderWithMimeMessage.
public void testJavaMailSenderWithMimeMessage() throws MessagingException {
MockJavaMailSender sender = new MockJavaMailSender();
sender.setHost("host");
sender.setUsername("username");
sender.setPassword("password");
MimeMessage mimeMessage = sender.createMimeMessage();
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("you@mail.org"));
sender.send(mimeMessage);
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(mimeMessage, sender.transport.getSentMessage(0));
}
use of javax.mail.internet.MimeMessage in project spring-framework by spring-projects.
the class JavaMailSenderTests method javaMailSenderWithMimeMessagePreparators.
@Test
public void javaMailSenderWithMimeMessagePreparators() {
MockJavaMailSender sender = new MockJavaMailSender();
sender.setHost("host");
sender.setUsername("username");
sender.setPassword("password");
final List<Message> messages = new ArrayList<>();
MimeMessagePreparator preparator1 = new MimeMessagePreparator() {
@Override
public void prepare(MimeMessage mimeMessage) throws MessagingException {
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("he@mail.org"));
messages.add(mimeMessage);
}
};
MimeMessagePreparator preparator2 = new MimeMessagePreparator() {
@Override
public void prepare(MimeMessage mimeMessage) throws MessagingException {
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("she@mail.org"));
messages.add(mimeMessage);
}
};
sender.send(preparator1, preparator2);
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(2, sender.transport.getSentMessages().size());
assertEquals(messages.get(0), sender.transport.getSentMessage(0));
assertEquals(messages.get(1), sender.transport.getSentMessage(1));
}
use of javax.mail.internet.MimeMessage in project camel by apache.
the class GmailUsersMessagesIntegrationTest method createTestEmail.
private Message createTestEmail() throws MessagingException, IOException {
com.google.api.services.gmail.model.Profile profile = requestBody("google-mail://users/getProfile?inBody=userId", CURRENT_USERID);
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage mm = new MimeMessage(session);
mm.addRecipients(javax.mail.Message.RecipientType.TO, profile.getEmailAddress());
mm.setSubject("Hello from camel-google-mail");
mm.setContent("Camel rocks!", "text/plain");
Message createMessageWithEmail = createMessageWithEmail(mm);
return createMessageWithEmail;
}
use of javax.mail.internet.MimeMessage in project camel by apache.
the class GmailUsersMessagesIntegrationTest method createMessageWithEmail.
private Message createMessageWithEmail(MimeMessage email) throws MessagingException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
email.writeTo(baos);
String encodedEmail = Base64.encodeBase64URLSafeString(baos.toByteArray());
Message message = new Message();
message.setRaw(encodedEmail);
return message;
}
use of javax.mail.internet.MimeMessage in project camel by apache.
the class GmailUsersThreadsIntegrationTest method createMessageWithEmail.
private Message createMessageWithEmail(MimeMessage email) throws MessagingException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
email.writeTo(baos);
String encodedEmail = Base64.encodeBase64URLSafeString(baos.toByteArray());
Message message = new Message();
message.setRaw(encodedEmail);
return message;
}
Aggregations