List of usage examples for javax.mail Message getRecipients
public abstract Address[] getRecipients(RecipientType type) throws MessagingException;
From source file:com.cubusmail.gwtui.server.services.ConvertUtil.java
/** * @param msg/*from www . j a va 2 s.co m*/ * @return * @throws MessagingException */ public static GWTMessage convert(Message msg) throws MessagingException { GWTMessage result = new GWTMessage(); result.setId(msg.getMessageNumber()); result.setSubject(msg.getSubject()); result.setFrom(MessageUtils.getMailAdressString(msg.getFrom(), AddressStringType.COMPLETE)); result.setTo(MessageUtils.getMailAdressString(msg.getRecipients(Message.RecipientType.TO), AddressStringType.COMPLETE)); result.setCc(MessageUtils.getMailAdressString(msg.getRecipients(Message.RecipientType.CC), AddressStringType.COMPLETE)); result.setDate(msg.getSentDate()); result.setSize(MessageUtils.calculateAttachmentSize(msg.getSize())); return result; }
From source file:search.java
public static void dumpPart(Part p) throws Exception { if (p instanceof Message) { Message m = (Message) p; Address[] a;// ww w .j av a 2 s . com // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) System.out.println("FROM: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) System.out.println("TO: " + a[j].toString()); } // SUBJECT System.out.println("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); System.out.println("SendDate: " + (d != null ? d.toLocaleString() : "UNKNOWN")); // FLAGS: Flags flags = m.getFlags(); StringBuffer sb = new StringBuffer(); Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags boolean first = true; for (int i = 0; i < sf.length; i++) { String s; Flags.Flag f = sf[i]; if (f == Flags.Flag.ANSWERED) s = "\\Answered"; else if (f == Flags.Flag.DELETED) s = "\\Deleted"; else if (f == Flags.Flag.DRAFT) s = "\\Draft"; else if (f == Flags.Flag.FLAGGED) s = "\\Flagged"; else if (f == Flags.Flag.RECENT) s = "\\Recent"; else if (f == Flags.Flag.SEEN) s = "\\Seen"; else continue; // skip it if (first) first = false; else sb.append(' '); sb.append(s); } String[] uf = flags.getUserFlags(); // get the user flag strings for (int i = 0; i < uf.length; i++) { if (first) first = false; else sb.append(' '); sb.append(uf[i]); } System.out.println("FLAGS = " + sb.toString()); } System.out.println("CONTENT-TYPE: " + p.getContentType()); /* Dump input stream InputStream is = ((MimeMessage)m).getInputStream(); int c; while ((c = is.read()) != -1) System.out.write(c); */ Object o = p.getContent(); if (o instanceof String) { System.out.println("This is a String"); System.out.println((String) o); } else if (o instanceof Multipart) { System.out.println("This is a Multipart"); Multipart mp = (Multipart) o; int count = mp.getCount(); for (int i = 0; i < count; i++) dumpPart(mp.getBodyPart(i)); } else if (o instanceof InputStream) { System.out.println("This is just an input stream"); InputStream is = (InputStream) o; int c; while ((c = is.read()) != -1) System.out.write(c); } }
From source file:search.java
public static void dumpPart(Part p) throws Exception { if (p instanceof Message) { Message m = (Message) p; Address[] a;/*from www . j a v a 2s . co m*/ // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) System.out.println("FROM: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) System.out.println("TO: " + a[j].toString()); } // SUBJECT System.out.println("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); System.out.println("SendDate: " + (d != null ? d.toLocaleString() : "UNKNOWN")); // FLAGS: Flags flags = m.getFlags(); StringBuffer sb = new StringBuffer(); Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags boolean first = true; for (int i = 0; i < sf.length; i++) { String s; Flags.Flag f = sf[i]; if (f == Flags.Flag.ANSWERED) s = "\\Answered"; else if (f == Flags.Flag.DELETED) s = "\\Deleted"; else if (f == Flags.Flag.DRAFT) s = "\\Draft"; else if (f == Flags.Flag.FLAGGED) s = "\\Flagged"; else if (f == Flags.Flag.RECENT) s = "\\Recent"; else if (f == Flags.Flag.SEEN) s = "\\Seen"; else continue; // skip it if (first) first = false; else sb.append(' '); sb.append(s); } String[] uf = flags.getUserFlags(); // get the user flag strings for (int i = 0; i < uf.length; i++) { if (first) first = false; else sb.append(' '); sb.append(uf[i]); } System.out.println("FLAGS = " + sb.toString()); } System.out.println("CONTENT-TYPE: " + p.getContentType()); /* * Dump input stream InputStream is = ((MimeMessage)m).getInputStream(); int * c; while ((c = is.read()) != -1) System.out.write(c); */ Object o = p.getContent(); if (o instanceof String) { System.out.println("This is a String"); System.out.println((String) o); } else if (o instanceof Multipart) { System.out.println("This is a Multipart"); Multipart mp = (Multipart) o; int count = mp.getCount(); for (int i = 0; i < count; i++) dumpPart(mp.getBodyPart(i)); } else if (o instanceof InputStream) { System.out.println("This is just an input stream"); InputStream is = (InputStream) o; int c; while ((c = is.read()) != -1) System.out.write(c); } }
From source file:uidmsgshow.java
public static void dumpEnvelope(Message m) throws Exception { System.out.println("This is the message envelope"); System.out.println("---------------------------"); Address[] a;// www . j a va2 s. c o m // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) System.out.println("FROM: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) System.out.println("TO: " + a[j].toString()); } // SUBJECT System.out.println("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); System.out.println("SendDate: " + (d != null ? d.toString() : "UNKNOWN")); // SIZE System.out.println("Size: " + m.getSize()); // FLAGS: Flags flags = m.getFlags(); StringBuffer sb = new StringBuffer(); Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags boolean first = true; for (int i = 0; i < sf.length; i++) { String s; Flags.Flag f = sf[i]; if (f == Flags.Flag.ANSWERED) s = "\\Answered"; else if (f == Flags.Flag.DELETED) s = "\\Deleted"; else if (f == Flags.Flag.DRAFT) s = "\\Draft"; else if (f == Flags.Flag.FLAGGED) s = "\\Flagged"; else if (f == Flags.Flag.RECENT) s = "\\Recent"; else if (f == Flags.Flag.SEEN) s = "\\Seen"; else continue; // skip it if (first) first = false; else sb.append(' '); sb.append(s); } String[] uf = flags.getUserFlags(); // get the user flag strings for (int i = 0; i < uf.length; i++) { if (first) first = false; else sb.append(' '); sb.append(uf[i]); } System.out.println("FLAGS = " + sb.toString()); // X-MAILER String[] hdrs = m.getHeader("X-Mailer"); if (hdrs != null) System.out.println("X-Mailer: " + hdrs[0]); else System.out.println("X-Mailer NOT available"); }
From source file:uidmsgshow.java
public static void dumpEnvelope(Message m) throws Exception { System.out.println("This is the message envelope"); System.out.println("---------------------------"); Address[] a;// www. j av a2 s. c o m // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) System.out.println("FROM: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) System.out.println("TO: " + a[j].toString()); } // SUBJECT System.out.println("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); System.out.println("SendDate: " + (d != null ? d.toString() : "UNKNOWN")); // SIZE System.out.println("Size: " + m.getSize()); // FLAGS: Flags flags = m.getFlags(); StringBuffer sb = new StringBuffer(); Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags boolean first = true; for (int i = 0; i < sf.length; i++) { String s; Flags.Flag f = sf[i]; if (f == Flags.Flag.ANSWERED) s = "\\Answered"; else if (f == Flags.Flag.DELETED) s = "\\Deleted"; else if (f == Flags.Flag.DRAFT) s = "\\Draft"; else if (f == Flags.Flag.FLAGGED) s = "\\Flagged"; else if (f == Flags.Flag.RECENT) s = "\\Recent"; else if (f == Flags.Flag.SEEN) s = "\\Seen"; else continue; // skip it if (first) first = false; else sb.append(' '); sb.append(s); } String[] uf = flags.getUserFlags(); // get the user flag strings for (int i = 0; i < uf.length; i++) { if (first) first = false; else sb.append(' '); sb.append(uf[i]); } System.out.println("FLAGS = " + sb.toString()); // X-MAILER String[] hdrs = m.getHeader("X-Mailer"); if (hdrs != null) System.out.println("X-Mailer: " + hdrs[0]); else System.out.println("X-Mailer NOT available"); }
From source file:MainClass.java
public static void dumpEnvelope(Message m) throws Exception { pr("This is the message envelope"); pr("---------------------------"); Address[] a;/*from ww w . j a va2 s . c o m*/ // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) pr("FROM: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) { pr("TO: " + a[j].toString()); InternetAddress ia = (InternetAddress) a[j]; if (ia.isGroup()) { InternetAddress[] aa = ia.getGroup(false); for (int k = 0; k < aa.length; k++) pr(" GROUP: " + aa[k].toString()); } } } // SUBJECT pr("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); pr("SendDate: " + (d != null ? d.toString() : "UNKNOWN")); // FLAGS Flags flags = m.getFlags(); StringBuffer sb = new StringBuffer(); Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags boolean first = true; for (int i = 0; i < sf.length; i++) { String s; Flags.Flag f = sf[i]; if (f == Flags.Flag.ANSWERED) s = "\\Answered"; else if (f == Flags.Flag.DELETED) s = "\\Deleted"; else if (f == Flags.Flag.DRAFT) s = "\\Draft"; else if (f == Flags.Flag.FLAGGED) s = "\\Flagged"; else if (f == Flags.Flag.RECENT) s = "\\Recent"; else if (f == Flags.Flag.SEEN) s = "\\Seen"; else continue; // skip it if (first) first = false; else sb.append(' '); sb.append(s); } String[] uf = flags.getUserFlags(); // get the user flag strings for (int i = 0; i < uf.length; i++) { if (first) first = false; else sb.append(' '); sb.append(uf[i]); } pr("FLAGS: " + sb.toString()); // X-MAILER String[] hdrs = m.getHeader("X-Mailer"); if (hdrs != null) pr("X-Mailer: " + hdrs[0]); else pr("X-Mailer NOT available"); }
From source file:com.email.ReceiveEmail.java
/** * Saved the list of all of the TO, FROM, CC, BCC, and dates * * @param m Message//from www. j a va2 s . c o m * @param p Part * @param eml EmailMessageModel * @return EmailMessageModel */ private static EmailMessageModel saveEnvelope(Message m, Part p, EmailMessageModel eml) { String to = ""; String cc = ""; String bcc = ""; try { Address[] address; //From if ((address = m.getFrom()) != null) { for (Address addy : address) { eml.setEmailFrom(addy.toString()); } } //to if ((address = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < address.length; j++) { if (j == 0) { to = address[j].toString(); } else { to += "; " + address[j].toString(); } } } eml.setEmailTo(removeEmojiAndSymbolFromString(to)); //CC if ((address = m.getRecipients(Message.RecipientType.CC)) != null) { for (int j = 0; j < address.length; j++) { if (j == 0) { cc = address[j].toString(); } else { cc += "; " + address[j].toString(); } } } eml.setEmailCC(removeEmojiAndSymbolFromString(cc)); //BCC if ((address = m.getRecipients(Message.RecipientType.BCC)) != null) { for (int j = 0; j < address.length; j++) { if (j == 0) { bcc = address[j].toString(); } else { bcc += "; " + address[j].toString(); } } } eml.setEmailBCC(removeEmojiAndSymbolFromString(bcc)); //subject if (m.getSubject() == null) { eml.setEmailSubject(""); } else { eml.setEmailSubject(removeEmojiAndSymbolFromString(m.getSubject().replace("'", "\""))); } //date eml.setSentDate(new java.sql.Timestamp(m.getSentDate().getTime())); eml.setReceivedDate(new java.sql.Timestamp(m.getReceivedDate().getTime())); //Get email body String emailBody = getEmailBodyText(p); // clean email Body emailBody = StringUtilities.replaceOfficeTags(emailBody); if (StringUtilities.isHtml(emailBody)) { Source htmlSource = new Source(emailBody); Segment htmlSeg = new Segment(htmlSource, 0, htmlSource.length()); Renderer htmlRend = new Renderer(htmlSeg); emailBody = htmlRend.toString(); } eml.setEmailBody(removeEmojiAndSymbolFromString(emailBody)); } catch (MessagingException ex) { ExceptionHandler.Handle(ex); } return eml; }
From source file:msgshow.java
public static void dumpEnvelope(Message m) throws Exception { pr("This is the message envelope"); pr("---------------------------"); Address[] a;//www. ja va 2s. c om // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) pr("FROM: " + a[j].toString()); } // REPLY TO if ((a = m.getReplyTo()) != null) { for (int j = 0; j < a.length; j++) pr("REPLY TO: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) { pr("TO: " + a[j].toString()); InternetAddress ia = (InternetAddress) a[j]; if (ia.isGroup()) { InternetAddress[] aa = ia.getGroup(false); for (int k = 0; k < aa.length; k++) pr(" GROUP: " + aa[k].toString()); } } } // SUBJECT pr("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); pr("SendDate: " + (d != null ? d.toString() : "UNKNOWN")); // FLAGS Flags flags = m.getFlags(); StringBuffer sb = new StringBuffer(); Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags boolean first = true; for (int i = 0; i < sf.length; i++) { String s; Flags.Flag f = sf[i]; if (f == Flags.Flag.ANSWERED) s = "\\Answered"; else if (f == Flags.Flag.DELETED) s = "\\Deleted"; else if (f == Flags.Flag.DRAFT) s = "\\Draft"; else if (f == Flags.Flag.FLAGGED) s = "\\Flagged"; else if (f == Flags.Flag.RECENT) s = "\\Recent"; else if (f == Flags.Flag.SEEN) s = "\\Seen"; else continue; // skip it if (first) first = false; else sb.append(' '); sb.append(s); } String[] uf = flags.getUserFlags(); // get the user flag strings for (int i = 0; i < uf.length; i++) { if (first) first = false; else sb.append(' '); sb.append(uf[i]); } pr("FLAGS: " + sb.toString()); // X-MAILER String[] hdrs = m.getHeader("X-Mailer"); if (hdrs != null) pr("X-Mailer: " + hdrs[0]); else pr("X-Mailer NOT available"); }
From source file:com.agiletec.plugins.jpwebmail.apsadmin.webmail.folder.WebmailAction.java
public Address[] getTo(Message message) throws Throwable { return message.getRecipients(Message.RecipientType.TO); }
From source file:info.raack.appliancedetection.common.email.SMTPEmailSender.java
public SMTPEmailSender() { emailProperties = new Properties(); emailProperties.put("mail.smtp.host", "smtp.gmail.com"); emailProperties.put("mail.smtp.socketFactory.port", "465"); emailProperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); emailProperties.put("mail.smtp.auth", "true"); emailProperties.put("mail.smtp.port", "465"); emailQueue = new LinkedBlockingQueue<Message>(); emailThread = new StoppableThread(new StoppableThreadAction() { public void doAction() throws InterruptedException { sendGeneralEmail(emailQueue.take()); }/*from w ww . j a va 2 s. c om*/ private void sendGeneralEmail(Message message) { try { logger.debug("Sending email to " + message.getRecipients(Message.RecipientType.TO)[0]); Transport.send(message); } catch (Exception e) { throw new RuntimeException("Could not send email", e); } } public String getName() { return "email sender"; } }); emailThread.start(); }