List of usage examples for javax.mail.internet InternetAddress getAddress
public String getAddress()
From source file:ninja.postoffice.commonsmail.CommonsmailHelperImpl.java
@Override public Tuple<String, String> createValidEmailFromString(String email) throws AddressException { InternetAddress internetAddress = new InternetAddress(email); Tuple<String, String> tuple = new Tuple<String, String>(internetAddress.getAddress(), internetAddress.getPersonal()); return tuple; }
From source file:org.sakaiproject.email.impl.TestEmailService.java
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())); }//from w w w . j a v a 2s. c om tos.put(type, addrs); } // add the actual recipients tos.put(RecipientType.ACTUAL, EmailAddress.toEmailAddress(to)); msg.setRecipients(tos); // add additional headers msg.setHeaders(additionalHeaders); // send message emailService.send(msg); }
From source file:org.sakaiproject.email.impl.TestEmailService.java
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())); }//from ww w .ja va 2s .co m tos.put(type, addrs); } // add the actual recipients tos.put(RecipientType.ACTUAL, EmailAddress.toEmailAddress(to)); msg.setRecipients(tos); // add additional headers msg.setHeaders(additionalHeaders); // add attachments msg.setAttachments(attachments); // send message emailService.send(msg); }
From source file:org.obm.push.mail.SendEmail.java
public SendEmail(InternetAddress defaultFrom, Message message) throws MimeException { Preconditions.checkNotNull(Strings.emptyToNull(defaultFrom.getAddress())); this.from = defaultFrom; this.originalMessage = message; setMessage(message);/* ww w . j a v a2 s.c o m*/ }
From source file:org.opencms.mail.TestCmsMail.java
/** * Tests sending mails to invalid email address.<p> *///from w ww . j a va 2 s. c o m public void testCmsInvalidMailAddress() { echo("Trying to send an HTML mail to invalid mail address ..."); String invalidMail = "abc@blockmail.de"; CmsHtmlMail mail = new CmsHtmlMail(); StringBuilder sb = new StringBuilder("<html><body>"); sb.append("<h1>Test mail containing HTML</h1>"); sb.append("<p>This is only a test mail for sending HTML mails.</p>"); sb.append( "<p><a href=\"http://www.opencms.org/\"><img src=\"http://www.opencms.org/export/system/modules/org.opencms.website.template/resources/img/logo/logo_opencms.gif\" border=\"0\"></a></p>"); sb.append("<p><a href=\"http://www.opencms.org/\">www.opencms.org</a>"); sb.append("</body></html>"); // EmailException will be caught here to test functionality required by // CmsMessageInfo.java try { mail.setHtmlMsg(sb.toString()); mail.addTo(invalidMail); mail.setSubject("OpenCms TestCase HTML Mail"); mail.setSmtpPort(SMTP_PORT); String messageID = mail.send(); assertNull(messageID); } catch (EmailException e) { // Check if root cause was SendFailedException due to rejected mail by SMTP server assertTrue(e.getCause() instanceof SendFailedException); SendFailedException sfe = (SendFailedException) e.getCause(); Address[] invalidAddresses = sfe.getInvalidAddresses(); InternetAddress invalidAddress = (InternetAddress) invalidAddresses[0]; echo("Invalid address was: " + invalidAddress.getAddress()); assertEquals(invalidMail, invalidAddress.getAddress()); } }
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: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 ww w . ja v a2 s .c om*/ 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) {//from w w w. j a va2 s. c o 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 ww . j a va 2 s .c om*/ 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.openkm.util.MailUtils.java
/** * Conversion from Address to String.//from w ww .j a v a2s.c o m */ public static String addressToString(Address a) { if (a != null) { InternetAddress ia = (InternetAddress) a; if (ia.getPersonal() != null) { return ia.getPersonal() + " <" + ia.getAddress() + ">"; } else { return ia.getAddress(); } } else { return ""; } }