use of javax.mail.Message in project vcell by virtualcell.
the class ListservMail method getBouncedEmails.
private static void getBouncedEmails(String emailPassword) throws Exception {
IMAPSSLStore store = null;
IMAPFolder[] inboxs = null;
BufferedWriter bw = null;
try {
// connect to mail server using imaps protocol
Properties properties = System.getProperties();
Session session = Session.getDefaultInstance(properties);
// Use this instead of pop3s to access non 'Inbox' folders
store = (IMAPSSLStore) session.getStore("imaps");
store.connect(mailServer, mailUser, emailPassword);
inboxs = new IMAPFolder[] { (IMAPFolder) store.getFolder(mailFolder) };
inboxs[0].open(Folder.READ_ONLY);
// get the list of messages from folder
Message[] messages = inboxs[0].getMessages();
if (messages.length == 0)
System.out.println("No messages found.");
for (int i = 0; i < messages.length; i++) {
// // stop after listing ten messages
// if (i > 10) {
// break;
// }
System.out.println("Message " + (i + 1));
IMAPMessage message = (IMAPMessage) messages[i];
System.out.println("From : " + message.getFrom()[0]);
System.out.println("Subject : " + message.getSubject());
System.out.println("Sent Date : " + message.getSentDate());
System.out.println("Type : " + message.getContentType());
if (message.getSubject().contains(subjectSearchForBounced)) {
readMessage(message, 0, 0);
}
System.out.println();
}
System.out.println("Found " + bouncedEMails.size() + " bounced emails");
bw = new BufferedWriter(new FileWriter(rawBounceFile));
for (String s : bouncedEMails) {
bw.write(s + "\n");
}
} finally {
if (bw != null) {
try {
bw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (inboxs != null) {
for (int i = 0; i < inboxs.length; i++) {
if (inboxs[i] != null && inboxs[i].isOpen()) {
try {
inboxs[i].close(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
if (store != null) {
try {
store.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of javax.mail.Message in project quickstart by wildfly.
the class Email method send.
/**
* Method to send the email based upon values entered in the JSF view. Exception should be handled in a production usage but
* is not handled in this example.
*
* @throws Exception
*/
public void send() throws Exception {
Message message = new MimeMessage(mySession);
message.setFrom(new InternetAddress(from));
Address toAddress = new InternetAddress(to);
message.addRecipient(Message.RecipientType.TO, toAddress);
message.setSubject(subject);
message.setContent(body, "text/plain");
Transport.send(message);
}
use of javax.mail.Message in project camel by apache.
the class MailIdempotentRepositoryDuplicateTest method prepareMailbox.
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("pop3");
store.connect("localhost", 25, "jones", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts 5 new messages
Message[] messages = new Message[5];
for (int i = 0; i < 5; i++) {
messages[i] = new MimeMessage(sender.getSession());
messages[i].setText("Message " + i);
messages[i].setHeader("Message-ID", "myuid-" + i);
}
folder.appendMessages(messages);
folder.close(true);
}
use of javax.mail.Message in project camel by apache.
the class MailMaxMessagesPerPollTest method prepareMailbox.
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("pop3");
store.connect("localhost", 25, "jones", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts 5 new messages
Message[] messages = new Message[5];
for (int i = 0; i < 5; i++) {
messages[i] = new MimeMessage(sender.getSession());
messages[i].setHeader("Message-ID", "" + i);
messages[i].setText("Message " + i);
}
folder.appendMessages(messages);
folder.close(true);
}
use of javax.mail.Message in project camel by apache.
the class MailBatchConsumerTest method prepareMailbox.
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("pop3");
store.connect("localhost", 25, "jones", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts 5 new messages
Message[] messages = new Message[5];
for (int i = 0; i < 5; i++) {
messages[i] = new MimeMessage(sender.getSession());
messages[i].setHeader("Message-ID", "" + i);
messages[i].setText("Message " + i);
}
folder.appendMessages(messages);
folder.close(true);
}
Aggregations