public List<Address> getFrom() throws MessagingException { return Arrays.asList(mimeMessage.getFrom()); }
Address[] from = originalMessage.getFrom(); if (from == null) { throw new MessagingException("Message failed RFC-2822 validation: No Sender"); putAddressListInAttributes(attributes, EMAIL_HEADER_CC, originalMessage.getRecipients(Message.RecipientType.CC)); putAddressListInAttributes(attributes, EMAIL_HEADER_BCC, originalMessage.getRecipients(Message.RecipientType.BCC)); putAddressListInAttributes(attributes, EMAIL_HEADER_FROM, originalMessage.getFrom()); // RFC-2822 specifies "From" as mailbox-list
Address[] from = originalMessage.getFrom(); if (from == null) { throw new MessagingException("Message failed RFC-2822 validation: No Sender");
@Test public void testMessageFactorySetFrom() throws MessagingException { final MimeMessageBuilder builder = new MimeMessageBuilder(null); final String address = "testing@example.com"; assertNull(builder.build().getFrom()); builder.setFrom(null); Address[] array = null; final Address addr = InternetAddress.getLocalAddress(null); if (addr != null) { array = new Address[] { addr }; } assertArrayEquals(array, builder.build().getFrom()); builder.setFrom(address); assertArrayEquals(new Address[] { new InternetAddress(address) }, builder.build().getFrom()); }
List<Address> froms = Arrays.asList(sentMessage.getFrom()); assertEquals(1, froms.size()); assertEquals("me@mail.org", ((InternetAddress) froms.get(0)).getAddress());
assertEquals("'singleobject'", msg.getContent()); assertEquals("'singleobject'", msg.getSubject()); assertEquals("from@domain.com", ((InternetAddress) msg.getFrom()[0]).getAddress()); assertEquals("replyTo@domain.com", ((InternetAddress) msg.getReplyTo()[0]).getAddress());
assertEquals(myBody, msg.getContent()); assertEquals(mySubject, msg.getSubject()); assertEquals("from@domain.com", ((InternetAddress) msg.getFrom()[0]).getAddress()); assertEquals("replyTo@domain.com", ((InternetAddress) msg.getReplyTo()[0]).getAddress());
/** * @return the 'from' field of the message * @throws Exception parsing the mime message failed */ public String getFrom() throws Exception { final javax.mail.Address[] addresses = this.mimeMessage.getFrom(); if (addresses == null || addresses.length == 0) { return null; } return ((InternetAddress) addresses[0]).getAddress(); }
/** * Return the value of the RFC 822 "Reply-To" header field. If * this header is unavailable or its value is absent, then * the <code>getFrom</code> method is called and its value is returned. * * This implementation uses the <code>getHeader</code> method * to obtain the requisite header field. * * @exception MessagingException for failures * @see #headers */ public Address[] getReplyTo() throws MessagingException { Address[] a = getAddressHeader("Reply-To"); if (a == null || a.length == 0) a = getFrom(); return a; }
/** * Return the value of the RFC 822 "Reply-To" header field. If * this header is unavailable or its value is absent, then * the <code>getFrom</code> method is called and its value is returned. * * This implementation uses the <code>getHeader</code> method * to obtain the requisite header field. * * @exception MessagingException for failures * @see #headers */ @Override public Address[] getReplyTo() throws MessagingException { Address[] a = getAddressHeader("Reply-To"); if (a == null || a.length == 0) a = getFrom(); return a; }
/** * Get the "From" attribute. */ public Address[] getFrom() throws MessagingException { checkExpunged(); if (bodyLoaded) return super.getFrom(); loadEnvelope(); InternetAddress[] a = envelope.from; /* * Per RFC 2822, the From header is required, and thus the IMAP * spec also requires that it be present, but we know that in * practice it is often missing. Some servers fill in the * From field with the Sender field in this case, but at least * Exchange 2007 does not. Use the same fallback strategy used * by MimeMessage. */ if (a == null || a.length == 0) a = envelope.sender; return aaclone(a); }
/** * Get the "From" attribute. */ @Override public Address[] getFrom() throws MessagingException { checkExpunged(); if (bodyLoaded) return super.getFrom(); loadEnvelope(); InternetAddress[] a = envelope.from; /* * Per RFC 2822, the From header is required, and thus the IMAP * spec also requires that it be present, but we know that in * practice it is often missing. Some servers fill in the * From field with the Sender field in this case, but at least * Exchange 2007 does not. Use the same fallback strategy used * by MimeMessage. */ if (a == null || a.length == 0) a = envelope.sender; return aaclone(a); }
/** * Computes the default to-address if none was specified. This can * fail if the local address can't be computed. * @param msg the message * @param type the recipient type. * @since JavaMail 1.5.0 */ private void setDefaultRecipient(final Message msg, final Message.RecipientType type) { try { Address a = InternetAddress.getLocalAddress(getSession(msg)); if (a != null) { msg.setRecipient(type, a); } else { final MimeMessage m = new MimeMessage(getSession(msg)); m.setFrom(); //Should throw an exception with a cause. Address[] from = m.getFrom(); if (from.length > 0) { msg.setRecipients(type, from); } else { throw new MessagingException("No local address."); } } } catch (MessagingException | RuntimeException ME) { reportError("Unable to compute a default recipient.", ME, ErrorManager.FORMAT_FAILURE); } }
final MimeMessage m = new MimeMessage(getSession(msg)); Address[] from = m.getFrom(); if (from.length > 0) { msg.setRecipients(type, from);
@Test public void testConvertToMimeMessage() throws Exception { EmailWrapper wrapper = getTypicalEmailWrapper(); MimeMessage email = new JavamailService().parseToEmail(wrapper); assertEquals(new InternetAddress(wrapper.getSenderEmail(), wrapper.getSenderName()), email.getFrom()[0]); assertEquals(new InternetAddress(wrapper.getReplyTo()), email.getReplyTo()[0]); assertEquals(new InternetAddress(wrapper.getRecipient()), email.getRecipients(Message.RecipientType.TO)[0]); assertEquals(new InternetAddress(wrapper.getBcc()), email.getRecipients(Message.RecipientType.BCC)[0]); assertEquals(wrapper.getSubject(), email.getSubject()); assertEquals(wrapper.getContent(), email.getContent().toString()); }
@Test public void testImap() throws Exception { Message<?> message = this.imapChannel.receive(10000); assertNotNull(message); MimeMessage mm = (MimeMessage) message.getPayload(); assertEquals("Foo <foo@bar>", mm.getRecipients(RecipientType.TO)[0].toString()); assertEquals("Bar <bar@baz>", mm.getFrom()[0].toString()); assertEquals("Test Email", mm.getSubject()); assertThat(mm.getContent(), equalTo(TestMailServer.MailServer.MailHandler.BODY + "\r\n")); }
Address[] fa; Address me; if (message != null && (fa = message.getFrom()) != null && fa.length > 0) me = fa[0];
Address[] fa; Address me; if (message != null && (fa = message.getFrom()) != null && fa.length > 0) me = fa[0];