javax.mail.internet.MimeMessage.getFrom()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(166)

本文整理了Java中javax.mail.internet.MimeMessage.getFrom()方法的一些代码示例,展示了MimeMessage.getFrom()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeMessage.getFrom()方法的具体详情如下:
包路径:javax.mail.internet.MimeMessage
类名称:MimeMessage
方法名:getFrom

MimeMessage.getFrom介绍

[英]Returns the value of the RFC 822 "From" header fields. If this header field is absent, the "Sender" header field is used. If the "Sender" header field is also absent, null is returned.

This implementation uses the getHeader method to obtain the requisite header field.
[中]返回RFC 822“From”头字段的值。如果缺少此标题字段,则使用“发件人”标题字段。如果“发件人”标题字段也不存在,则返回null
此实现使用getHeader方法来获取必需的头字段。

代码示例

代码示例来源:origin: cloudfoundry/uaa

public List<Address> getFrom() throws MessagingException {
  return Arrays.asList(mimeMessage.getFrom());
}

代码示例来源:origin: apache/nifi

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

代码示例来源:origin: apache/nifi

Address[] from = originalMessage.getFrom();
if (from == null) {
  throw new MessagingException("Message failed RFC-2822 validation: No Sender");

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@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());
}

代码示例来源:origin: spring-projects/spring-framework

List<Address> froms = Arrays.asList(sentMessage.getFrom());
assertEquals(1, froms.size());
assertEquals("me@mail.org", ((InternetAddress) froms.get(0)).getAddress());

代码示例来源:origin: kiegroup/jbpm

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());

代码示例来源:origin: kiegroup/jbpm

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());

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * @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();
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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;
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * 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;
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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);
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * 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);
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * 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);
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

final MimeMessage m = new MimeMessage(getSession(msg));
Address[] from = m.getFrom();
if (from.length > 0) {
  msg.setRecipients(type, from);

代码示例来源:origin: TEAMMATES/teammates

@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());
}

代码示例来源:origin: spring-projects/spring-integration

@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"));
}

代码示例来源:origin: camunda/camunda-bpm-platform

Address[] fa;
Address me;
if (message != null && (fa = message.getFrom()) != null &&
  fa.length > 0)
me = fa[0];

代码示例来源:origin: com.sun.mail/javax.mail

Address[] fa;
Address me;
if (message != null && (fa = message.getFrom()) != null &&
  fa.length > 0)
me = fa[0];

代码示例来源:origin: com.sun.mail/javax.mail

final Address[] any = all.length != 0 ? all : abort.getFrom();
  if (any != null && any.length != 0) {
    t = session.getTransport(any[0]);
Address[] from = abort.getFrom();
Address sender = abort.getSender();
if (sender instanceof InternetAddress) {

代码示例来源:origin: camunda/camunda-bpm-platform

final Address[] any = all.length != 0 ? all : abort.getFrom();
  if (any != null && any.length != 0) {
    t = session.getTransport(any[0]);
Address[] from = abort.getFrom();
Address sender = abort.getSender();
if (sender instanceof InternetAddress) {

相关文章

MimeMessage类方法