本文整理了Java中javax.mail.internet.MimeMessage.addRecipients()
方法的一些代码示例,展示了MimeMessage.addRecipients()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeMessage.addRecipients()
方法的具体详情如下:
包路径:javax.mail.internet.MimeMessage
类名称:MimeMessage
方法名:addRecipients
[英]Add the given addresses to the specified recipient type.
[中]将给定地址添加到指定的收件人类型。
代码示例来源:origin: cloudfoundry/uaa
@Override
public void sendMessage(String email, MessageType messageType, String subject, String htmlContent) {
MimeMessage message = mailSender.createMimeMessage();
try {
message.addFrom(getSenderAddresses());
message.addRecipients(Message.RecipientType.TO, email);
message.setSubject(subject);
message.setContent(htmlContent, "text/html");
} catch (MessagingException e) {
logger.error("Exception raised while sending message to " + email, e);
} catch (UnsupportedEncodingException e) {
logger.error("Exception raised while sending message to " + email, e);
}
mailSender.send(message);
}
}
代码示例来源:origin: HubSpot/Singularity
private void sendMail(List<String> toList, List<String> ccList, String subject, String body) {
final SMTPConfiguration smtpConfiguration = maybeSmtpConfiguration.get();
boolean useAuth = false;
if (smtpConfiguration.getUsername().isPresent() && smtpConfiguration.getPassword().isPresent()) {
useAuth = true;
} else if (smtpConfiguration.getUsername().isPresent() || smtpConfiguration.getPassword().isPresent()) {
LOG.warn("Not using smtp authentication because username ({}) or password ({}) was not present", smtpConfiguration.getUsername().isPresent(), smtpConfiguration.getPassword().isPresent());
}
try {
final Session session = createSession(smtpConfiguration, useAuth);
MimeMessage message = new MimeMessage(session);
Address[] toArray = getAddresses(toList);
message.addRecipients(RecipientType.TO, toArray);
if (!ccList.isEmpty()) {
Address[] ccArray = getAddresses(ccList);
message.addRecipients(RecipientType.CC, ccArray);
}
message.setFrom(new InternetAddress(smtpConfiguration.getFrom()));
message.setSubject(MimeUtility.encodeText(subject, "utf-8", null));
message.setContent(body, "text/html; charset=utf-8");
LOG.trace("Sending a message to {} - {}", Arrays.toString(toArray), getEmailLogFormat(toList, subject));
Transport.send(message);
} catch (Throwable t) {
LOG.warn("Unable to send message {}", getEmailLogFormat(toList, subject), t);
exceptionNotifier.notify(String.format("Unable to send message (%s)", t.getMessage()), t, ImmutableMap.of("subject", subject));
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
if (a != null && a.length > 0) {
if (replyallcc)
reply.addRecipients(Message.RecipientType.CC, a);
else
reply.addRecipients(Message.RecipientType.TO, a);
reply.addRecipients(Message.RecipientType.CC, a);
代码示例来源:origin: com.sun.mail/javax.mail
if (a != null && a.length > 0) {
if (replyallcc)
reply.addRecipients(Message.RecipientType.CC, a);
else
reply.addRecipients(Message.RecipientType.TO, a);
reply.addRecipients(Message.RecipientType.CC, a);
代码示例来源:origin: mtdhb/api
private void addRecipients(MimeMessage message, RecipientType type, String recipients) throws MessagingException {
String[] addresses = recipients.split(";");
for (int i = 0; i < addresses.length; i++) {
message.addRecipients(type, addresses[i]);
}
}
代码示例来源:origin: hf-hf/mail-micro-service
/**
* 追加发件人
* @author hf-hf
* @date 2018/12/27 15:36
*/
private void addRecipients(MimeMessage message, Message.RecipientType type,
String recipients) throws MessagingException {
String[] addresses = recipients.split(";");
for (int i = 0; i < addresses.length; i++) {
message.addRecipients(type, addresses[i]);
}
}
代码示例来源:origin: opencast/opencast
/**
* Process an array of recipients with the given {@link javax.mail.Message.RecipientType}
*
* @param message
* The message to add the recipients to
* @param type
* The type of recipient
* @param addresses
* @throws MessagingException
*/
private static void addRecipients(MimeMessage message, RecipientType type, String... strAddresses)
throws MessagingException {
if (strAddresses != null) {
InternetAddress[] addresses = new InternetAddress[strAddresses.length];
for (int i = 0; i < strAddresses.length; i++)
addresses[i] = new InternetAddress(strAddresses[i]);
message.addRecipients(type, addresses);
}
}
代码示例来源:origin: org.apache.james/james-server-core-library
/**
* @see javax.mail.Message#addRecipients(javax.mail.Message.RecipientType, javax.mail.Address[])
*/
public void addRecipients(Message.RecipientType type, Address[] addresses)
throws MessagingException {
getWrappedMessageForWriting().addRecipients(type, addresses);
}
代码示例来源:origin: org.apache.james/james-server-core-library
/**
* @see javax.mail.internet.MimeMessage#addRecipients(javax.mail.Message.RecipientType, java.lang.String)
*/
public void addRecipients(Message.RecipientType type, String addresses)
throws MessagingException {
getWrappedMessageForWriting().addRecipients(type, addresses);
}
代码示例来源:origin: org.eclipse.scout.rt/org.eclipse.scout.commons
@Override
public void addRecipients(Message.RecipientType type, String addresses) throws MessagingException {
if (type == RecipientType.NEWSGROUPS) {
super.addRecipients(type, addresses);
}
else {
addRecipients(type, InternetAddress.parse(addresses));
}
}
代码示例来源:origin: kodokojo/kodokojo
private static void addRecipients(MimeMessage message, javax.mail.Message.RecipientType recipientType, List<String> address) throws MessagingException {
if (CollectionUtils.isNotEmpty(address)) {
message.addRecipients(recipientType, convertListToAddresses(address));
}
}
代码示例来源:origin: org.eclipse.scout.rt/org.eclipse.scout.commons
@Override
public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException {
super.addRecipients(type, encodeAddresses(addresses));
}
代码示例来源:origin: OpenClinica/OpenClinica
public void process(String to, String from, String subject, String body) throws MessagingException {
InternetAddress from2 = new InternetAddress(from);
message.setFrom(from2);
// InternetAddress to2 = new InternetAddress(to);
// message.addRecipient(Message.RecipientType.TO, to2);
message.addRecipients(Message.RecipientType.TO, processMultipleImailAddresses(to));
message.setSubject(subject);
// YW <<
mbp.setContent(body, "text/plain");
// YW >>
mm.addBodyPart(mbp);
message.setContent(mm);
Transport.send(message);
}
代码示例来源:origin: OpenClinica/OpenClinica
public void processHtml(String to, String from, String subject, String body) throws MessagingException {
InternetAddress from2 = new InternetAddress(from);
message.setFrom(from2);
// InternetAddress to2 = new InternetAddress(to);
// message.addRecipient(Message.RecipientType.TO, to2);
message.addRecipients(Message.RecipientType.TO, processMultipleImailAddresses(to));
message.setSubject(subject);
// YW <<
mbp.setContent(body, "text/html");
// YW >>
mm.addBodyPart(mbp);
message.setContent(mm);
Transport.send(message);
}
代码示例来源:origin: org.apache.camel/camel-mail
private static void appendRecipientToMimeMessage(MimeMessage mimeMessage, MailConfiguration configuration, Exchange exchange,
String type, String recipient) throws MessagingException, IOException {
List<InternetAddress> recipientsAddresses = new ArrayList<>();
for (String line : splitRecipients(recipient)) {
String address = line.trim();
// Only add the address which is not empty
if (ObjectHelper.isNotEmpty(address)) {
recipientsAddresses.add(asEncodedInternetAddress(address, determineCharSet(configuration, exchange)));
}
}
mimeMessage.addRecipients(asRecipientType(type), recipientsAddresses.toArray(new InternetAddress[recipientsAddresses.size()]));
}
代码示例来源:origin: io.github.aktoluna/slnarch-common
private void addAddress(MimeMessage mimeMessage, RecipientType recipientType, String address)
throws MessagingException {
InternetAddress[] addresses = parseAddress(address);
if (addresses != null) {
logger.info("add {} address={}", recipientType.toString(), address);
mimeMessage.addRecipients(recipientType, addresses);
}
}
代码示例来源:origin: com.meltmedia.cadmium/cadmium-email
/**
* Populates a mime message with the recipient addresses, from address, reply to address, and the subject.
*/
protected void populate( MimeMessage message )
throws MessagingException
{
// add all of the to addresses.
message.addRecipients(Message.RecipientType.TO, toSet.toInternetAddressArray());
message.addRecipients(Message.RecipientType.CC, ccSet.toInternetAddressArray());
message.addRecipients(Message.RecipientType.BCC, bccSet.toInternetAddressArray());
message.setFrom(from);
if( replyTo != null ) {
message.setReplyTo(new InternetAddress[] {replyTo});
}
if( subject != null ) {
message.setSubject(subject);
}
}
代码示例来源:origin: groupon/DotCi
public MimeMessage createEmail(DynamicBuild build, BuildListener listener) throws AddressException, MessagingException {
List<InternetAddress> to = getToEmailAddress(build, listener);
String from = SetupConfig.get().getFromEmailAddress();
Session session = Session.getDefaultInstance(System.getProperties());
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipients(Message.RecipientType.TO, to.toArray(new InternetAddress[to.size()]));
String subject = getNotificationMessage(build, listener);
message.setSubject(subject);
message.setText("Link to the build " + build.getAbsoluteUrl());
return message;
}
代码示例来源:origin: stackoverflow.com
private static void sendMailSSL(String host, int port, String user, String pass, String to, String from, String subj, String message) throws UnsupportedEncodingException, MessagingException
{
Properties props = System.getProperties();
props.put("mail.smtps.ssl.checkserveridentity", true);
Session session = Session.getDefaultInstance(props, null);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from, from));
msg.addRecipients(RecipientType.TO, to);
msg.setSubject(subj);
msg.setText(message);
Transport t = session.getTransport("smtps");
try {
t.connect(host, port, user, pass);
t.sendMessage(msg, msg.getAllRecipients());
} finally {
t.close();
}
}
代码示例来源:origin: com.caucho/resin
/**
* Sends to a mailbox
*/
public void send(String subject, String body)
{
try {
MimeMessage msg = new MimeMessage(getSession());
if(_from.length > 0)
msg.addFrom(_from);
msg.addRecipients(RecipientType.TO, _to);
if(subject != null)
msg.setSubject(subject);
msg.setContent(body, "text/plain");
send(msg);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!