本文整理了Java中javax.mail.Message.addRecipient()
方法的一些代码示例,展示了Message.addRecipient()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.addRecipient()
方法的具体详情如下:
包路径:javax.mail.Message
类名称:Message
方法名:addRecipient
[英]Add this recipient address to the existing ones of the given type.
The default implementation uses the addRecipients
method.
[中]将此收件人地址添加到给定类型的现有收件人地址。
默认实现使用addRecipients
方法。
代码示例来源:origin: azkaban/azkaban
message.setFrom(from);
for (final String toAddr : this._toAddress) {
message.addRecipient(Message.RecipientType.TO, new InternetAddress(
toAddr, false));
代码示例来源:origin: aws/aws-sdk-java
m.addRecipient(addressTable.get(a), a);
代码示例来源:origin: azkaban/azkaban
@Test
public void testSendEmail() throws Exception {
this.em.setTLS("true");
this.em.addToAddress(this.toAddr);
this.em.setFromAddress(this.sender);
this.em.setSubject("azkaban test email");
this.em.setBody("azkaban test email");
this.em.sendEmail();
verify(this.mimeMessage).addRecipient(RecipientType.TO, this.addresses[0]);
verify(this.mailSender).sendMessage(this.mimeMessage, this.addresses);
}
代码示例来源:origin: IanDarwin/javasrc
public void addCCRecipient(String message_cc) throws MessagingException {
// CC Address
InternetAddress ccAddress = new InternetAddress(message_cc);
mesg.addRecipient(Message.RecipientType.CC, ccAddress);
}
代码示例来源:origin: IanDarwin/javasrc
public void addRecipient(String message_recip) throws MessagingException {
// TO Address
InternetAddress toAddress = new InternetAddress(message_recip);
mesg.addRecipient(Message.RecipientType.TO, toAddress);
}
代码示例来源:origin: org.openwfe/openwfe-applic
/**
* Given a recipient list (email addresses separated by commas), adds them
* to the message.
*/
public static void addRecipients
(final Message m,
final RecipientType recipientType,
final String recipientList)
throws
MessagingException
{
if (recipientList == null) return;
final String[] ss = recipientList.split(", *");
for (int i=0; i<ss.length; i++)
m.addRecipient(recipientType, new InternetAddress(ss[i]));
}
代码示例来源:origin: stackoverflow.com
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("xxxx@gmail.com", "xxxx"));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress("user@testdomain.com,"Mr. User"));
msg.setSubject("Test email from GAE/J development");
msg.setText("This is test:);
Transport.send(msg);
} catch (Exception e) {
e.printStackTrace();
}
代码示例来源:origin: google/mail-importer
@Override
public void addRecipient(RecipientType type, Address address)
throws RuntimeMessagingException {
try {
delegate.addRecipient(type, address);
} catch (MessagingException e) {
throw new RuntimeMessagingException(e);
}
}
代码示例来源:origin: LiveRamp/hank
private void sendEmails(Set<String> emailTargets, String body) throws IOException, InterruptedException {
Session session = Session.getDefaultInstance(emailSessionProperties);
Message message = new MimeMessage(session);
try {
message.setSubject("Hank monitor: " + name);
message.setFrom(new InternetAddress(emailFrom));
for (String emailTarget : emailTargets) {
message.addRecipient(Message.RecipientType.TO, new InternetAddress(emailTarget));
}
message.setContent(body, "text/html");
Transport.send(message);
} catch (MessagingException e) {
throw new RuntimeException("Failed to send notification email.", e);
}
}
代码示例来源:origin: opencredo/test-automation-quickstart
public void sendTestEmail() throws MessagingException, UnsupportedEncodingException {
String msgBody = "This is a test email generated by the Opencredo Test Framework!";
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("test@opencredo-testing.com", "OpenCredo tester"));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(this.emailAddress, "Test email recipient"));
msg.setSubject(TEST_EMAIL_SUBJECT);
msg.setText(msgBody);
Transport.send(msg);
}
代码示例来源:origin: stackoverflow.com
private Message createMessage(String email, String subject, String messageBody, Session session) throws MessagingException, UnsupportedEncodingException {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("tutorials@tiemenschut.com", "Tiemen Schut"));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(email, email));
message.setSubject(subject);
message.setText(messageBody);
return message;
}
代码示例来源:origin: jlfex/hermes
/**
* 添加收件地址
*
* @param address
*/
public void addTo(String address) {
try {
message.addRecipient(RecipientType.TO, new InternetAddress(address));
} catch (AddressException e) {
throw new ServiceException("cannot add address " + address + ".", "exception.mail.to", e);
} catch (MessagingException e) {
throw new ServiceException("cannot add address " + address + ".", "exception.mail.to", e);
}
}
代码示例来源:origin: jlfex/hermes
/**
* 添加暗送地址
*
* @param address
*/
public void addBcc(String address) {
try {
message.addRecipient(RecipientType.BCC, new InternetAddress(address));
} catch (AddressException e) {
throw new ServiceException("cannot add address " + address + ".", "exception.mail.bcc", e);
} catch (MessagingException e) {
throw new ServiceException("cannot add address " + address + ".", "exception.mail.bcc", e);
}
}
代码示例来源:origin: jlfex/hermes
/**
* 添加抄送地址
*
* @param address
*/
public void addCc(String address) {
try {
message.addRecipient(RecipientType.CC, new InternetAddress(address));
} catch (AddressException e) {
throw new ServiceException("cannot add address " + address + ".", "exception.mail.cc", e);
} catch (MessagingException e) {
throw new ServiceException("cannot add address " + address + ".", "exception.mail.cc", e);
}
}
代码示例来源:origin: stackoverflow.com
Message message = new MimeMessage(session);
message.setDataHandler(new DataHandler(new ByteArrayDataSource(csv.getBytes("8859_8"),
"text/csv")));
message.setFileName("data.csv");
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Query report...");
Transport.send(message);
LOG.info("Sent message successfully ...");
代码示例来源:origin: stackoverflow.com
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("admin@domain.com", "Admin", "UTF-8"));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(recipientAddress));
msg.setSubject(emailSubject);
msg.setText(emailText);
Transport.send(msg);
} catch (AddressException e) {
// TO address not valid
} catch (MessagingException e) {
// other email error
} catch (UnsupportedEncodingException e) {
// should not happen UTF-8 is always available
}
代码示例来源:origin: spajus/gmail4j
@Override
public void addTo(final EmailAddress to) {
try {
if (to.hasName()) {
source.addRecipient(RecipientType.TO,
new InternetAddress(to.getEmail(), to.getName()));
} else {
source.addRecipient(RecipientType.TO,
new InternetAddress(to.getEmail()));
}
} catch (final Exception e) {
throw new GmailException("Failed adding To recipient", e);
}
}
代码示例来源:origin: stackoverflow.com
// Create a email session
Session session = Session.getInstance(props);
// Create a new Message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(FROM));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(TO));
msg.setSubject(SUBJECT);
msg.setText(BODY);
msg.saveChanges();
// Reuse one Transport object for sending all your messages
// for better performance
Transport t = new AWSJavaMailTransport(session, null);
t.connect();
t.sendMessage(msg, null);
代码示例来源:origin: org.codemonkey.simplejavamail/simple-java-mail
/**
* Fills the {@link Message} instance with recipients from the {@link Email}.
*
* @param email The message in which the recipients are defined.
* @param message The javax message that needs to be filled with recipients.
* @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
* @throws MessagingException See {@link Message#addRecipient(javax.mail.Message.RecipientType, Address)}
*/
private static void setRecipients(final Email email, final Message message)
throws UnsupportedEncodingException, MessagingException {
for (final Recipient recipient : email.getRecipients()) {
final Address address = new InternetAddress(recipient.getAddress(), recipient.getName(), CHARACTER_ENCODING);
message.addRecipient(recipient.getType(), address);
}
}
代码示例来源:origin: org.simplejavamail/simple-java-mail
/**
* Fills the {@link Message} instance with recipients from the {@link Email}.
*
* @param email The message in which the recipients are defined.
* @param message The javax message that needs to be filled with recipients.
* @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
* @throws MessagingException See {@link Message#addRecipient(Message.RecipientType, Address)}
*/
private static void setRecipients(final Email email, final Message message)
throws UnsupportedEncodingException, MessagingException {
for (final Recipient recipient : email.getRecipients()) {
final Address address = new InternetAddress(recipient.getAddress(), recipient.getName(), CHARACTER_ENCODING);
message.addRecipient(recipient.getType(), address);
}
}
内容来源于网络,如有侵权,请联系作者删除!