本文整理了Java中javax.mail.Message.setRecipients()
方法的一些代码示例,展示了Message.setRecipients()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.setRecipients()
方法的具体详情如下:
包路径:javax.mail.Message
类名称:Message
方法名:setRecipients
[英]Set the recipient addresses. All addresses of the specified type are replaced by the addresses parameter.
[中]设置收件人地址。指定类型的所有地址都将替换为addresses参数。
代码示例来源:origin: log4j/log4j
/**
* Address message.
* @param msg message, may not be null.
* @throws MessagingException thrown if error addressing message.
* @since 1.2.14
*/
protected void addressMessage(final Message msg) throws MessagingException {
if (from != null) {
msg.setFrom(getAddress(from));
} else {
msg.setFrom();
}
//Add ReplyTo addresses if defined.
if (replyTo != null && replyTo.length() > 0) {
msg.setReplyTo(parseAddress(replyTo));
}
if (to != null && to.length() > 0) {
msg.setRecipients(Message.RecipientType.TO, parseAddress(to));
}
//Add CC receipients if defined.
if (cc != null && cc.length() > 0) {
msg.setRecipients(Message.RecipientType.CC, parseAddress(cc));
}
//Add BCC receipients if defined.
if (bcc != null && bcc.length() > 0) {
msg.setRecipients(Message.RecipientType.BCC, parseAddress(bcc));
}
}
代码示例来源:origin: pentaho/pentaho-kettle
addressTo[i] = new InternetAddress( strArrRecipients[i] );
msg.setRecipients( Message.RecipientType.TO, addressTo );
代码示例来源:origin: stackoverflow.com
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("to_email_address@domain.com"));
message.setSubject("Testing Subject");
代码示例来源:origin: javaee-samples/javaee7-samples
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(creds.getTo()));
message.setSubject("Sending message using Programmatic JavaMail " + Calendar.getInstance().getTime());
代码示例来源:origin: javaee-samples/javaee7-samples
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(creds.getTo()));
message.setSubject("Sending message using Annotated JavaMail "
+ Calendar.getInstance().getTime());
代码示例来源:origin: pentaho/pentaho-kettle
addressTo[i] = new InternetAddress( strArrRecipients[i] );
msg.setRecipients( Message.RecipientType.TO, addressTo );
代码示例来源:origin: aws/aws-sdk-java
m.setRecipients(Message.RecipientType.TO, new Address[0]);
m.setRecipients(Message.RecipientType.CC, new Address[0]);
m.setRecipients(Message.RecipientType.BCC, new Address[0]);
代码示例来源:origin: JpressProjects/jpress
@Override
public void send(Email email) {
if (enable == false) {
//do nothing
return;
}
Message message = createMessage();
try {
message.setSubject(email.getSubject());
message.setContent(email.getContent(), "text/html;charset=utf-8");
message.setRecipients(Message.RecipientType.TO, toAddress(email.getTo()));
message.setRecipients(Message.RecipientType.CC, toAddress(email.getCc()));
Transport.send(message);
} catch (MessagingException e) {
logger.error("SimpleEmailSender send error", e);
}
}
}
代码示例来源:origin: javamelody/javamelody
final InternetAddress[] toAddresses = InternetAddress.parse(toAddress, false);
final Message msg = new MimeMessage(getSession());
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
代码示例来源:origin: pentaho/pentaho-kettle
msg.setRecipients( Message.RecipientType.TO, address );
msg.setRecipients( Message.RecipientType.CC, addressCc );
msg.setRecipients( Message.RecipientType.BCC, addressBCc );
代码示例来源:origin: apache/nifi
@Override
public void notify(final NotificationContext context, final NotificationType notificationType, final String subject, final String messageText) throws NotificationFailedException {
final Properties properties = getMailProperties(context);
final Session mailSession = createMailSession(properties);
final Message message = new MimeMessage(mailSession);
try {
message.setFrom(InternetAddress.parse(context.getProperty(FROM).evaluateAttributeExpressions().getValue())[0]);
final InternetAddress[] toAddresses = toInetAddresses(context.getProperty(TO).evaluateAttributeExpressions().getValue());
message.setRecipients(RecipientType.TO, toAddresses);
final InternetAddress[] ccAddresses = toInetAddresses(context.getProperty(CC).evaluateAttributeExpressions().getValue());
message.setRecipients(RecipientType.CC, ccAddresses);
final InternetAddress[] bccAddresses = toInetAddresses(context.getProperty(BCC).evaluateAttributeExpressions().getValue());
message.setRecipients(RecipientType.BCC, bccAddresses);
message.setHeader("X-Mailer", context.getProperty(HEADER_XMAILER).evaluateAttributeExpressions().getValue());
message.setSubject(subject);
final String contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
message.setContent(messageText, contentType);
message.setSentDate(new Date());
Transport.send(message);
} catch (final ProcessException | MessagingException e) {
throw new NotificationFailedException("Failed to send E-mail Notification", e);
}
}
代码示例来源:origin: pentaho/pentaho-kettle
address[i] = new InternetAddress( destinations[i] );
msg.setRecipients( Message.RecipientType.TO, address );
msg.setRecipients( Message.RecipientType.CC, addressCc );
msg.setRecipients( Message.RecipientType.BCC, addressBCc );
代码示例来源:origin: apache/nifi
message.setRecipients(RecipientType.TO, toInetAddresses(context, flowFile, TO));
message.setRecipients(RecipientType.CC, toInetAddresses(context, flowFile, CC));
message.setRecipients(RecipientType.BCC, toInetAddresses(context, flowFile, BCC));
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Set the recipient address. All addresses of the specified
* type are replaced by the address parameter. <p>
*
* The default implementation uses the <code>setRecipients</code> method.
*
* @param type the recipient type
* @param address the address
* @exception IllegalWriteException if the underlying
* implementation does not support modification
* of existing values
* @exception MessagingException for other failures
*/
public void setRecipient(RecipientType type, Address address)
throws MessagingException {
if (address == null)
setRecipients(type, null);
else {
Address[] a = new Address[1];
a[0] = address;
setRecipients(type, a);
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Set the recipient address. All addresses of the specified
* type are replaced by the address parameter. <p>
*
* The default implementation uses the <code>setRecipients</code> method.
*
* @param type the recipient type
* @param address the address
* @exception IllegalWriteException if the underlying
* implementation does not support modification
* of existing values
* @exception MessagingException for other failures
*/
public void setRecipient(RecipientType type, Address address)
throws MessagingException {
if (address == null)
setRecipients(type, null);
else {
Address[] a = new Address[1];
a[0] = address;
setRecipients(type, a);
}
}
代码示例来源:origin: stackoverflow.com
Properties properties = System.getProperties();
properties.put("mail.smtp.host", server);
properties.put("mail.smtp.port", "" + port);
Session session = Session.getInstance(properties);
Transport transport = session.getTransport("smtp");
transport.connect(server, username, password);
for (int i = 0; i < count; i++) {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
message.setRecipients(Message.RecipientType.TO, address);
message.setSubject(subject + "JavaMail API");
message.setSentDate(new Date());
setHTMLContent(message);
message.saveChanges();
transport.sendMessage(message, address);
}
transport.close();
代码示例来源:origin: apache/log4j
/**
* Address message.
* @param msg message, may not be null.
* @throws MessagingException thrown if error addressing message.
* @since 1.2.14
*/
protected void addressMessage(final Message msg) throws MessagingException {
if (from != null) {
msg.setFrom(getAddress(from));
} else {
msg.setFrom();
}
//Add ReplyTo addresses if defined.
if (replyTo != null && replyTo.length() > 0) {
msg.setReplyTo(parseAddress(replyTo));
}
if (to != null && to.length() > 0) {
msg.setRecipients(Message.RecipientType.TO, parseAddress(to));
}
//Add CC receipients if defined.
if (cc != null && cc.length() > 0) {
msg.setRecipients(Message.RecipientType.CC, parseAddress(cc));
}
//Add BCC receipients if defined.
if (bcc != null && bcc.length() > 0) {
msg.setRecipients(Message.RecipientType.BCC, parseAddress(bcc));
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Sets the recipient for the given message.
* @param msg the message.
* @param key the key to search in the session.
* @param type the recipient type.
* @return true if the key was contained in the session.
*/
private boolean setRecipient(final Message msg,
final String key, final Message.RecipientType type) {
boolean containsKey;
final String value = getSession(msg).getProperty(key);
containsKey = value != null;
if (!isEmpty(value)) {
try {
final Address[] address = InternetAddress.parse(value, false);
if (address.length > 0) {
msg.setRecipients(type, address);
}
} catch (final MessagingException ME) {
reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
}
}
return containsKey;
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Sets the recipient for the given message.
* @param msg the message.
* @param key the key to search in the session.
* @param type the recipient type.
* @return true if the key was contained in the session.
*/
private boolean setRecipient(final Message msg,
final String key, final Message.RecipientType type) {
boolean containsKey;
final String value = getSession(msg).getProperty(key);
containsKey = value != null;
if (!isEmpty(value)) {
try {
final Address[] address = InternetAddress.parse(value, false);
if (address.length > 0) {
msg.setRecipients(type, address);
}
} catch (final MessagingException ME) {
reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
}
}
return containsKey;
}
代码示例来源: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);
}
}
内容来源于网络,如有侵权,请联系作者删除!