javax.mail.Message.addFrom()方法的使用及代码示例

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

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

Message.addFrom介绍

[英]Add these addresses to the existing "From" attribute
[中]将这些地址添加到现有的“发件人”属性中

代码示例

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

message.addFrom(toInetAddresses(context, flowFile, FROM));
message.setRecipients(RecipientType.TO, toInetAddresses(context, flowFile, TO));
message.setRecipients(RecipientType.CC, toInetAddresses(context, flowFile, CC));

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

/**
 * Sets from address header.
 * @param msg the target message.
 */
private void setFrom(final Message msg) {
  final String from = getSession(msg).getProperty("mail.from");
  if (from != null) {
    try {
      final Address[] address = InternetAddress.parse(from, false);
      if (address.length > 0) {
        if (address.length == 1) {
          msg.setFrom(address[0]);
        } else { //Greater than 1 address.
          msg.addFrom(address);
        }
      }
      //Can't place an else statement here because the 'from' is
      //not null which causes the local address computation
      //to fail.  Assume the user wants to omit the from address
      //header.
    } catch (final MessagingException ME) {
      reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
      setDefaultFrom(msg);
    }
  } else {
    setDefaultFrom(msg);
  }
}

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

/**
 * Sets from address header.
 * @param msg the target message.
 */
private void setFrom(final Message msg) {
  final String from = getSession(msg).getProperty("mail.from");
  if (from != null) {
    try {
      final Address[] address = InternetAddress.parse(from, false);
      if (address.length > 0) {
        if (address.length == 1) {
          msg.setFrom(address[0]);
        } else { //Greater than 1 address.
          msg.addFrom(address);
        }
      }
      //Can't place an else statement here because the 'from' is
      //not null which causes the local address computation
      //to fail.  Assume the user wants to omit the from address
      //header.
    } catch (final MessagingException ME) {
      reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
      setDefaultFrom(msg);
    }
  } else {
    setDefaultFrom(msg);
  }
}

代码示例来源:origin: google/mail-importer

@Override
public void addFrom(Address[] addresses) throws RuntimeMessagingException {
 try {
  delegate.addFrom(addresses);
 } catch (MessagingException e) {
  throw new RuntimeMessagingException(e);
 }
}

代码示例来源:origin: stackoverflow.com

public class SendEmailGood {
  private final Supplier<Message> messageSupplier;
  private final Consumer<Message> messageSender;

  public SendEmailGood(Supplier<Message> messageSupplier,
             Consumer<Message> messageSender) {
    this.messageSupplier = messageSupplier;
    this.messageSender = messageSender;
  }

  public void send(String[] addresses, String from, 
           String subject, String body) 
           throws MessagingException {
    Message message = messageSupplier.get();
    for (String address : addresses) {
      message.addRecipient
       (Message.RecipientType.TO, new InternetAddress(address));
    }
    message.addFrom(new InternetAddress[]{new InternetAddress(from)});
    message.setSubject(subject);
    message.setText(body);
    messageSender.accept(message);
  } 
}

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

private void setMessageHeader(Message msg, SLAEvent event) throws MessagingException {
  Address[] from = new InternetAddress[] { fromAddr };
  Address[] to;
  StringBuilder subject = new StringBuilder();
  to = parseAddress(event.getAlertContact());
  if (to == null) {
    LOG.error("Destination address is null or invalid, stop sending SLA alert email");
    throw new IllegalArgumentException("Destination address is not specified properly");
  }
  subject.append("OOZIE - SLA ");
  subject.append(event.getEventStatus().name());
  subject.append(" (AppName=");
  subject.append(event.getAppName());
  subject.append(", JobID=");
  subject.append(event.getId());
  subject.append(")");
  try {
    msg.addFrom(from);
    msg.addRecipients(RecipientType.TO, to);
    msg.setSubject(subject.toString());
  }
  catch (MessagingException me) {
    LOG.error("Message Exception in setting message header of SLA alert email", me);
    throw me;
  }
}

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

private void setMessageHeader(Message msg, SLAEvent event) throws MessagingException {
  Address[] from = new InternetAddress[] { fromAddr };
  Address[] to;
  StringBuilder subject = new StringBuilder();
  to = parseAddress(event.getAlertContact());
  if (to == null) {
    LOG.error("Destination address is null or invalid, stop sending SLA alert email");
    throw new IllegalArgumentException("Destination address is not specified properly");
  }
  subject.append("OOZIE - SLA ");
  subject.append(event.getEventStatus().name());
  subject.append(" (AppName=");
  subject.append(event.getAppName());
  subject.append(", JobID=");
  subject.append(event.getId());
  subject.append(")");
  try {
    msg.addFrom(from);
    msg.addRecipients(RecipientType.TO, to);
    msg.setSubject(subject.toString());
  }
  catch (MessagingException me) {
    LOG.error("Message Exception in setting message header of SLA alert email", me);
    throw me;
  }
}

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

private void setFrom(final Message msg, final Properties props) {
  final String from = props.getProperty("mail.from");
  if (from != null && from.length() > 0) {
    try {
      final Address[] address = InternetAddress.parse(from, false);
      if (address == null || address.length == 0) {
        setDefaultFrom(msg);
      } else {
        if (address.length == 1) {
          msg.setFrom(address[0]);
        } else { //Greater than 1 address.
          msg.addFrom(address);
        }
      }
    } catch (final MessagingException ME) {
      reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
      setDefaultFrom(msg);
    }
  } else {
    setDefaultFrom(msg);
  }
}

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

/**
 * Sets from address header.
 * @param msg the target message.
 */
private void setFrom(final Message msg) {
  final String from = getSession(msg).getProperty("mail.from");
  if (from != null) {
    try {
      final Address[] address = InternetAddress.parse(from, false);
      if (address.length > 0) {
        if (address.length == 1) {
          msg.setFrom(address[0]);
        } else { //Greater than 1 address.
          msg.addFrom(address);
        }
      }
      //Can't place an else statement here because the 'from' is
      //not null which causes the local address computation
      //to fail.  Assume the user wants to omit the from address
      //header.
    } catch (final MessagingException ME) {
      reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
      setDefaultFrom(msg);
    }
  } else {
    setDefaultFrom(msg);
  }
}

代码示例来源:origin: jboss/jboss-javaee-specs

/**
 * Sets from address header.
 * @param msg the target message.
 */
private void setFrom(final Message msg) {
  final String from = getSession(msg).getProperty("mail.from");
  if (from != null) {
    try {
      final Address[] address = InternetAddress.parse(from, false);
      if (address.length > 0) {
        if (address.length == 1) {
          msg.setFrom(address[0]);
        } else { //Greater than 1 address.
          msg.addFrom(address);
        }
      }
      //Can't place an else statement here because the 'from' is
      //not null which causes the local address computation
      //to fail.  Assume the user wants to omit the from address
      //header.
    } catch (final MessagingException ME) {
      reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
      setDefaultFrom(msg);
    }
  } else {
    setDefaultFrom(msg);
  }
}

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

/**
 * Sets from address header.
 * @param msg the target message.
 */
private void setFrom(final Message msg) {
  final String from = getSession(msg).getProperty("mail.from");
  if (from != null) {
    try {
      final Address[] address = InternetAddress.parse(from, false);
      if (address.length > 0) {
        if (address.length == 1) {
          msg.setFrom(address[0]);
        } else { //Greater than 1 address.
          msg.addFrom(address);
        }
      }
      //Can't place an else statement here because the 'from' is
      //not null which causes the local address computation
      //to fail.  Assume the user wants to omit the from address
      //header.
    } catch (final MessagingException ME) {
      reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
      setDefaultFrom(msg);
    }
  } else {
    setDefaultFrom(msg);
  }
}

代码示例来源:origin: org.glassfish.metro/webservices-extra

/**
 * Sets from address header.
 * @param msg the target message.
 */
private void setFrom(final Message msg) {
  final String from = getSession(msg).getProperty("mail.from");
  if (from != null) {
    try {
      final Address[] address = InternetAddress.parse(from, false);
      if (address.length > 0) {
        if (address.length == 1) {
          msg.setFrom(address[0]);
        } else { //Greater than 1 address.
          msg.addFrom(address);
        }
      }
      //Can't place an else statement here because the 'from' is
      //not null which causes the local address computation
      //to fail.  Assume the user wants to omit the from address
      //header.
    } catch (final MessagingException ME) {
      reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
      setDefaultFrom(msg);
    }
  } else {
    setDefaultFrom(msg);
  }
}

代码示例来源:origin: edu.internet2.middleware.grouper/grouperClient

message.addFrom(new InternetAddress[] { new InternetAddress(theFrom) });

代码示例来源:origin: org.apache.nifi/nifi-standard-processors

message.addFrom(toInetAddresses(context, flowFile, FROM));
message.setRecipients(RecipientType.TO, toInetAddresses(context, flowFile, TO));
message.setRecipients(RecipientType.CC, toInetAddresses(context, flowFile, CC));

相关文章