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

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

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

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

  1. message.setFrom(from);
  2. for (final String toAddr : this._toAddress) {
  3. message.addRecipient(Message.RecipientType.TO, new InternetAddress(
  4. toAddr, false));

代码示例来源:origin: aws/aws-sdk-java

  1. m.addRecipient(addressTable.get(a), a);

代码示例来源:origin: azkaban/azkaban

  1. @Test
  2. public void testSendEmail() throws Exception {
  3. this.em.setTLS("true");
  4. this.em.addToAddress(this.toAddr);
  5. this.em.setFromAddress(this.sender);
  6. this.em.setSubject("azkaban test email");
  7. this.em.setBody("azkaban test email");
  8. this.em.sendEmail();
  9. verify(this.mimeMessage).addRecipient(RecipientType.TO, this.addresses[0]);
  10. verify(this.mailSender).sendMessage(this.mimeMessage, this.addresses);
  11. }

代码示例来源:origin: IanDarwin/javasrc

  1. public void addCCRecipient(String message_cc) throws MessagingException {
  2. // CC Address
  3. InternetAddress ccAddress = new InternetAddress(message_cc);
  4. mesg.addRecipient(Message.RecipientType.CC, ccAddress);
  5. }

代码示例来源:origin: IanDarwin/javasrc

  1. public void addRecipient(String message_recip) throws MessagingException {
  2. // TO Address
  3. InternetAddress toAddress = new InternetAddress(message_recip);
  4. mesg.addRecipient(Message.RecipientType.TO, toAddress);
  5. }

代码示例来源:origin: org.openwfe/openwfe-applic

  1. /**
  2. * Given a recipient list (email addresses separated by commas), adds them
  3. * to the message.
  4. */
  5. public static void addRecipients
  6. (final Message m,
  7. final RecipientType recipientType,
  8. final String recipientList)
  9. throws
  10. MessagingException
  11. {
  12. if (recipientList == null) return;
  13. final String[] ss = recipientList.split(", *");
  14. for (int i=0; i<ss.length; i++)
  15. m.addRecipient(recipientType, new InternetAddress(ss[i]));
  16. }

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

  1. try {
  2. Message msg = new MimeMessage(session);
  3. msg.setFrom(new InternetAddress("xxxx@gmail.com", "xxxx"));
  4. msg.addRecipient(Message.RecipientType.TO,
  5. new InternetAddress("user@testdomain.com,"Mr. User"));
  6. msg.setSubject("Test email from GAE/J development");
  7. msg.setText("This is test:);
  8. Transport.send(msg);
  9. } catch (Exception e) {
  10. e.printStackTrace();
  11. }

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

  1. @Override
  2. public void addRecipient(RecipientType type, Address address)
  3. throws RuntimeMessagingException {
  4. try {
  5. delegate.addRecipient(type, address);
  6. } catch (MessagingException e) {
  7. throw new RuntimeMessagingException(e);
  8. }
  9. }

代码示例来源:origin: LiveRamp/hank

  1. private void sendEmails(Set<String> emailTargets, String body) throws IOException, InterruptedException {
  2. Session session = Session.getDefaultInstance(emailSessionProperties);
  3. Message message = new MimeMessage(session);
  4. try {
  5. message.setSubject("Hank monitor: " + name);
  6. message.setFrom(new InternetAddress(emailFrom));
  7. for (String emailTarget : emailTargets) {
  8. message.addRecipient(Message.RecipientType.TO, new InternetAddress(emailTarget));
  9. }
  10. message.setContent(body, "text/html");
  11. Transport.send(message);
  12. } catch (MessagingException e) {
  13. throw new RuntimeException("Failed to send notification email.", e);
  14. }
  15. }

代码示例来源:origin: opencredo/test-automation-quickstart

  1. public void sendTestEmail() throws MessagingException, UnsupportedEncodingException {
  2. String msgBody = "This is a test email generated by the Opencredo Test Framework!";
  3. Message msg = new MimeMessage(session);
  4. msg.setFrom(new InternetAddress("test@opencredo-testing.com", "OpenCredo tester"));
  5. msg.addRecipient(Message.RecipientType.TO, new InternetAddress(this.emailAddress, "Test email recipient"));
  6. msg.setSubject(TEST_EMAIL_SUBJECT);
  7. msg.setText(msgBody);
  8. Transport.send(msg);
  9. }

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

  1. private Message createMessage(String email, String subject, String messageBody, Session session) throws MessagingException, UnsupportedEncodingException {
  2. Message message = new MimeMessage(session);
  3. message.setFrom(new InternetAddress("tutorials@tiemenschut.com", "Tiemen Schut"));
  4. message.addRecipient(Message.RecipientType.TO, new InternetAddress(email, email));
  5. message.setSubject(subject);
  6. message.setText(messageBody);
  7. return message;
  8. }

代码示例来源:origin: jlfex/hermes

  1. /**
  2. * 添加收件地址
  3. *
  4. * @param address
  5. */
  6. public void addTo(String address) {
  7. try {
  8. message.addRecipient(RecipientType.TO, new InternetAddress(address));
  9. } catch (AddressException e) {
  10. throw new ServiceException("cannot add address " + address + ".", "exception.mail.to", e);
  11. } catch (MessagingException e) {
  12. throw new ServiceException("cannot add address " + address + ".", "exception.mail.to", e);
  13. }
  14. }

代码示例来源:origin: jlfex/hermes

  1. /**
  2. * 添加暗送地址
  3. *
  4. * @param address
  5. */
  6. public void addBcc(String address) {
  7. try {
  8. message.addRecipient(RecipientType.BCC, new InternetAddress(address));
  9. } catch (AddressException e) {
  10. throw new ServiceException("cannot add address " + address + ".", "exception.mail.bcc", e);
  11. } catch (MessagingException e) {
  12. throw new ServiceException("cannot add address " + address + ".", "exception.mail.bcc", e);
  13. }
  14. }

代码示例来源:origin: jlfex/hermes

  1. /**
  2. * 添加抄送地址
  3. *
  4. * @param address
  5. */
  6. public void addCc(String address) {
  7. try {
  8. message.addRecipient(RecipientType.CC, new InternetAddress(address));
  9. } catch (AddressException e) {
  10. throw new ServiceException("cannot add address " + address + ".", "exception.mail.cc", e);
  11. } catch (MessagingException e) {
  12. throw new ServiceException("cannot add address " + address + ".", "exception.mail.cc", e);
  13. }
  14. }

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

  1. Message message = new MimeMessage(session);
  2. message.setDataHandler(new DataHandler(new ByteArrayDataSource(csv.getBytes("8859_8"),
  3. "text/csv")));
  4. message.setFileName("data.csv");
  5. message.setFrom(new InternetAddress(from));
  6. message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
  7. message.setSubject("Query report...");
  8. Transport.send(message);
  9. LOG.info("Sent message successfully ...");

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

  1. Properties props = new Properties();
  2. Session session = Session.getDefaultInstance(props, null);
  3. try {
  4. Message msg = new MimeMessage(session);
  5. msg.setFrom(new InternetAddress("admin@domain.com", "Admin", "UTF-8"));
  6. msg.addRecipient(Message.RecipientType.TO, new InternetAddress(recipientAddress));
  7. msg.setSubject(emailSubject);
  8. msg.setText(emailText);
  9. Transport.send(msg);
  10. } catch (AddressException e) {
  11. // TO address not valid
  12. } catch (MessagingException e) {
  13. // other email error
  14. } catch (UnsupportedEncodingException e) {
  15. // should not happen UTF-8 is always available
  16. }

代码示例来源:origin: spajus/gmail4j

  1. @Override
  2. public void addTo(final EmailAddress to) {
  3. try {
  4. if (to.hasName()) {
  5. source.addRecipient(RecipientType.TO,
  6. new InternetAddress(to.getEmail(), to.getName()));
  7. } else {
  8. source.addRecipient(RecipientType.TO,
  9. new InternetAddress(to.getEmail()));
  10. }
  11. } catch (final Exception e) {
  12. throw new GmailException("Failed adding To recipient", e);
  13. }
  14. }

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

  1. // Create a email session
  2. Session session = Session.getInstance(props);
  3. // Create a new Message
  4. Message msg = new MimeMessage(session);
  5. msg.setFrom(new InternetAddress(FROM));
  6. msg.addRecipient(Message.RecipientType.TO, new InternetAddress(TO));
  7. msg.setSubject(SUBJECT);
  8. msg.setText(BODY);
  9. msg.saveChanges();
  10. // Reuse one Transport object for sending all your messages
  11. // for better performance
  12. Transport t = new AWSJavaMailTransport(session, null);
  13. t.connect();
  14. t.sendMessage(msg, null);

代码示例来源:origin: org.codemonkey.simplejavamail/simple-java-mail

  1. /**
  2. * Fills the {@link Message} instance with recipients from the {@link Email}.
  3. *
  4. * @param email The message in which the recipients are defined.
  5. * @param message The javax message that needs to be filled with recipients.
  6. * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
  7. * @throws MessagingException See {@link Message#addRecipient(javax.mail.Message.RecipientType, Address)}
  8. */
  9. private static void setRecipients(final Email email, final Message message)
  10. throws UnsupportedEncodingException, MessagingException {
  11. for (final Recipient recipient : email.getRecipients()) {
  12. final Address address = new InternetAddress(recipient.getAddress(), recipient.getName(), CHARACTER_ENCODING);
  13. message.addRecipient(recipient.getType(), address);
  14. }
  15. }

代码示例来源:origin: org.simplejavamail/simple-java-mail

  1. /**
  2. * Fills the {@link Message} instance with recipients from the {@link Email}.
  3. *
  4. * @param email The message in which the recipients are defined.
  5. * @param message The javax message that needs to be filled with recipients.
  6. * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
  7. * @throws MessagingException See {@link Message#addRecipient(Message.RecipientType, Address)}
  8. */
  9. private static void setRecipients(final Email email, final Message message)
  10. throws UnsupportedEncodingException, MessagingException {
  11. for (final Recipient recipient : email.getRecipients()) {
  12. final Address address = new InternetAddress(recipient.getAddress(), recipient.getName(), CHARACTER_ENCODING);
  13. message.addRecipient(recipient.getType(), address);
  14. }
  15. }

相关文章