List of usage examples for javax.mail.internet InternetAddress getPersonal
public String getPersonal()
From source file:org.echocat.jomon.net.mail.Mail.java
@Nonnull public Mail withRecipient(@Nonnull InternetAddress internetAddress) { return withRecipient(TO, internetAddress.getAddress(), internetAddress.getPersonal()); }
From source file:org.sakaiproject.email.impl.test.EmailServiceTest.java
@Test public void testSendMessageWithoutAttachments() throws Exception { // create message with from, subject, content EmailMessage msg = new EmailMessage(from.getAddress(), subject, content); // add message recipients that appear in the header HashMap<RecipientType, List<EmailAddress>> tos = new HashMap<RecipientType, List<EmailAddress>>(); for (RecipientType type : headerToMap.keySet()) { ArrayList<EmailAddress> addrs = new ArrayList<EmailAddress>(); for (InternetAddress iaddr : headerToMap.get(type)) { addrs.add(new EmailAddress(iaddr.getAddress(), iaddr.getPersonal())); }// ww w. j ava 2s . c o m tos.put(type, addrs); } // add the actual recipients LinkedList<EmailAddress> addys = new LinkedList<EmailAddress>(); for (InternetAddress t : to) { addys.add(new EmailAddress(t.getAddress(), t.getPersonal())); } tos.put(RecipientType.ACTUAL, addys); msg.setRecipients(tos); // add additional headers msg.setHeaders(additionalHeaders); // send message emailService.send(msg); }
From source file:org.sakaiproject.email.impl.test.EmailServiceTest.java
@Test public void testSendEmailMessage() throws Exception { // create message with from, subject, content EmailMessage msg = new EmailMessage(from.getAddress(), subject + " with attachments", content); // add message recipients that appear in the header HashMap<RecipientType, List<EmailAddress>> tos = new HashMap<RecipientType, List<EmailAddress>>(); for (RecipientType type : headerToMap.keySet()) { ArrayList<EmailAddress> addrs = new ArrayList<EmailAddress>(); for (InternetAddress iaddr : headerToMap.get(type)) { addrs.add(new EmailAddress(iaddr.getAddress(), iaddr.getPersonal())); }// www .j a va 2s . c om tos.put(type, addrs); } // add the actual recipients LinkedList<EmailAddress> addys = new LinkedList<EmailAddress>(); for (InternetAddress t : to) { addys.add(new EmailAddress(t.getAddress(), t.getPersonal())); } tos.put(RecipientType.ACTUAL, addys); msg.setRecipients(tos); // add additional headers msg.setHeaders(additionalHeaders); // add attachments msg.setAttachments(attachments); // send message emailService.send(msg); }
From source file:org.nuxeo.cm.mail.actionpipe.ExtractMessageInformation.java
@Override @SuppressWarnings("deprecation") public boolean execute(ExecutionContext context) throws MessagingException { File tmpOutput = null;/*from w w w . ja v a2 s. c o m*/ OutputStream out = null; try { Message originalMessage = context.getMessage(); if (log.isDebugEnabled()) { log.debug("Transforming message, original subject: " + originalMessage.getSubject()); } // fully load the message before trying to parse to // override most of server bugs, see // http://java.sun.com/products/javamail/FAQ.html#imapserverbug Message message; if (originalMessage instanceof MimeMessage) { message = new MimeMessage((MimeMessage) originalMessage); if (log.isDebugEnabled()) { log.debug("Transforming message after full load: " + message.getSubject()); } } else { // stuck with the original one message = originalMessage; } Address[] from = message.getFrom(); if (from != null) { Address addr = from[0]; if (addr instanceof InternetAddress) { InternetAddress iAddr = (InternetAddress) addr; context.put(SENDER_KEY, iAddr.getPersonal()); context.put(SENDER_EMAIL_KEY, iAddr.getAddress()); } else { context.put(SENDER_KEY, addr.toString()); } } Date receivedDate = message.getReceivedDate(); if (receivedDate == null) { // try to get header manually String[] dateHeader = message.getHeader("Date"); if (dateHeader != null) { try { long time = Date.parse(dateHeader[0]); receivedDate = new Date(time); } catch (IllegalArgumentException e) { // nevermind } } } if (receivedDate != null) { Calendar date = Calendar.getInstance(); date.setTime(receivedDate); context.put(RECEPTION_DATE_KEY, date); } String subject = message.getSubject(); if (subject != null) { subject = subject.trim(); } if (subject == null || "".equals(subject)) { subject = "<Unknown>"; } context.put(SUBJECT_KEY, subject); String[] messageIdHeader = message.getHeader("Message-ID"); if (messageIdHeader != null) { context.put(MESSAGE_ID_KEY, messageIdHeader[0]); } // TODO: pass it through initial context MimetypeRegistry mimeService = (MimetypeRegistry) context.getInitialContext().get(MIMETYPE_SERVICE_KEY); if (mimeService == null) { log.error("Could not retrieve mimetype service"); } // add all content as first blob tmpOutput = File.createTempFile("injectedEmail", ".eml"); Framework.trackFile(tmpOutput, tmpOutput); out = new FileOutputStream(tmpOutput); message.writeTo(out); Blob blob = Blobs.createBlob(tmpOutput, MESSAGE_RFC822_MIMETYPE, null, subject + ".eml"); List<Blob> blobs = new ArrayList<>(); blobs.add(blob); context.put(ATTACHMENTS_KEY, blobs); // process content getAttachmentParts(message, subject, mimeService, context); return true; } catch (IOException e) { log.error(e); } finally { IOUtils.closeQuietly(out); } return false; }
From source file:gov.nih.nci.firebird.service.messages.email.EmailServiceImplTest.java
@Test public void testSendMessage() throws MessagingException, IOException { bean.sendMessage(TEST_TO_ADDRESS, TEST_CC_ADDRESSES, TEST_BOUNCE_ADDRESS, testMessage); Message message = mailbox.get(0);//from w w w . j a v a2 s . com InternetAddress fromAddress = (InternetAddress) message.getFrom()[0]; assertEquals(TEST_FROM_ADDRESS, fromAddress.getAddress()); assertEquals(TEST_FROM_NAME, fromAddress.getPersonal()); InternetAddress toAddress = (InternetAddress) message.getRecipients(RecipientType.TO)[0]; assertEquals(TEST_TO_ADDRESS, toAddress.getAddress()); assertEquals(2, message.getRecipients(RecipientType.CC).length); InternetAddress ccAddress1 = (InternetAddress) message.getRecipients(RecipientType.CC)[0]; InternetAddress ccAddress2 = (InternetAddress) message.getRecipients(RecipientType.CC)[1]; assertEquals(TEST_CC_ADDRESSES.get(0), ccAddress1.getAddress()); assertEquals(TEST_CC_ADDRESSES.get(1), ccAddress2.getAddress()); assertEquals(TEST_SUBJECT, message.getSubject()); assertEquals(TEST_CONTENT, message.getContent()); }
From source file:com.jaeksoft.searchlib.crawler.mailbox.crawler.MailboxAbstractCrawler.java
private void putAddresses(IndexDocument document, Address[] addresses, String fieldEmail, String fieldPersonal) {//w ww . java 2 s.co m if (addresses == null) return; for (Address address : addresses) { if (address == null) continue; if (!(address instanceof InternetAddress)) continue; InternetAddress ia = (InternetAddress) address; document.addString(fieldEmail, ia.getAddress()); document.addString(fieldPersonal, ia.getPersonal()); } }
From source file:gov.nih.nci.firebird.service.messages.email.EmailServiceImplTest.java
private String doSendMessageTest(List<String> cc) throws MessagingException, IOException { String overrideEmail = "overrideEmail@example.com"; mailbox = Mailbox.get(overrideEmail); bean.setOverrideEmailAddress(overrideEmail); bean.sendMessage(TEST_TO_ADDRESS, cc, null, testMessage); Message message = mailbox.get(0);// w w w .j a v a 2 s . co m InternetAddress fromAddress = (InternetAddress) message.getFrom()[0]; assertEquals(TEST_FROM_ADDRESS, fromAddress.getAddress()); assertEquals(TEST_FROM_NAME, fromAddress.getPersonal()); InternetAddress toAddress = (InternetAddress) message.getRecipients(RecipientType.TO)[0]; assertEquals(overrideEmail, toAddress.getAddress()); assertNull(message.getRecipients(RecipientType.CC)); assertEquals(TEST_SUBJECT, message.getSubject()); assertTrue(message.getContent().toString().contains(TEST_CONTENT)); assertTrue(message.getContent().toString().contains(EmailServiceImpl.TO_OVERRIDE_HEADING)); assertTrue(message.getContent().toString().contains(TEST_TO_ADDRESS)); assertTrue(message.getContent().toString().contains(EmailServiceImpl.LINE_SEPARATOR)); return message.getContent().toString(); }
From source file:com.szmslab.quickjavamail.receive.MessageLoader.java
/** * InternetAddress??MailAddress??????/*from w w w .j ava 2 s .c o m*/ * * @param addresses * InternetAddress?? * @return MailAddress? */ private List<MailAddress> toMailAddressList(InternetAddress[] addresses) { List<MailAddress> list = new ArrayList<MailAddress>(); if (addresses != null) { for (InternetAddress address : addresses) { list.add(new MailAddress(address.getAddress(), address.getPersonal())); } } return list; }
From source file:com.googlecode.gmail4j.javamail.JavaMailGmailMessage.java
/** * Gets a {@link List} of {@link EmailAddress} by {@link RecipientType} * //from w w w . j a v a 2 s .c om * @param type Recipient type * @return List of Addresses * @throws MessagingException in case something is wrong */ private List<EmailAddress> getAddresses(final RecipientType type) throws MessagingException { final List<EmailAddress> addresses = new ArrayList<EmailAddress>(); for (final Address addr : source.getRecipients(type)) { final InternetAddress temp = (InternetAddress) addr; addresses.add(new EmailAddress(temp.getPersonal(), temp.getAddress())); } return addresses; }
From source file:com.duroty.application.open.manager.OpenManager.java
/** * DOCUMENT ME!//from ww w .ja va 2 s . c o m * * @param msession DOCUMENT ME! * @param from DOCUMENT ME! * @param to DOCUMENT ME! * @param username DOCUMENT ME! * @param password DOCUMENT ME! * @param signature DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ private void notifyToAdmins(Session msession, InternetAddress from, InternetAddress[] to, String user) throws Exception { try { HtmlEmail email = new HtmlEmail(); email.setMailSession(msession); email.setFrom(from.getAddress(), from.getPersonal()); HashSet aux = new HashSet(to.length); Collections.addAll(aux, to); email.setTo(aux); email.setSubject("User register in Duroty System"); email.setHtmlMsg( "<p>The user solicits register into the system</p><p>The user is: <b>" + user + "</b></p>"); email.setCharset(MimeUtility.javaCharset(Charset.defaultCharset().displayName())); email.send(); } finally { } }