Java Code Examples for javax.mail.Message#RecipientType
The following examples show how to use
javax.mail.Message#RecipientType .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageHelper.java From FairEmail with GNU General Public License v3.0 | 6 votes |
private static void addAddress(String email, Message.RecipientType type, MimeMessage imessage, EntityIdentity identity) throws MessagingException { List<Address> result = new ArrayList<>(); Address[] existing = imessage.getRecipients(type); if (existing != null) result.addAll(Arrays.asList(existing)); Address[] all = imessage.getAllRecipients(); Address[] addresses = convertAddress(InternetAddress.parse(email), identity); for (Address address : addresses) { boolean found = false; if (all != null) for (Address a : all) if (equalEmail(a, address)) { found = true; break; } if (!found) result.add(address); } imessage.setRecipients(type, result.toArray(new Address[0])); }
Example 2
Source File: MailServerImpl.java From webcurator with Apache License 2.0 | 6 votes |
private void addRecipient(Message message, String emails, Message.RecipientType rType) throws MessagingException, AddressException { if (emails != null && emails.length() > 0) { if (emails.contains(";")) { for (String email: emails.split(";")) { message.addRecipient(rType, new InternetAddress(email)); } } else { message.addRecipient(rType, new InternetAddress(emails)); } } }
Example 3
Source File: MailSender.java From iaf with Apache License 2.0 | 6 votes |
private void setRecipient(MailSession mailSession, MimeMessage msg, StringBuffer sb) throws UnsupportedEncodingException, MessagingException, SenderException { boolean recipientsFound = false; List<EMail> emailList = mailSession.getRecipientList(); for (EMail recipient : emailList) { String value = recipient.getAddress(); String type = recipient.getType(); Message.RecipientType recipientType; if ("cc".equalsIgnoreCase(type)) { recipientType = Message.RecipientType.CC; } else if ("bcc".equalsIgnoreCase(type)) { recipientType = Message.RecipientType.BCC; } else { recipientType = Message.RecipientType.TO; } msg.addRecipient(recipientType, new InternetAddress(value, recipient.getName())); recipientsFound = true; if (log.isDebugEnabled()) { sb.append("[recipient [" + recipient + "]]"); } } if (!recipientsFound) { throw new SenderException("MailSender [" + getName() + "] did not find any valid recipients"); } }
Example 4
Source File: MailUtils.java From scada with MIT License | 6 votes |
/** * �����ռ������ͣ���ȡ�ʼ��ռ��ˡ����ͺ����͵�ַ������ռ�������Ϊ�գ��������е��ռ��� * <p>Message.RecipientType.TO �ռ���</p> * <p>Message.RecipientType.CC ����</p> * <p>Message.RecipientType.BCC ����</p> * @param msg �ʼ����� * @param type �ռ������� * @return �ռ���1 <�ʼ���ַ1>, �ռ���2 <�ʼ���ַ2>, ... */ public static String getReceiveAddress(MimeMessage msg, Message.RecipientType type) throws MessagingException { StringBuffer receiveAddress = new StringBuffer(); Address[] addresss = null; if (type == null) { addresss = msg.getAllRecipients(); } else { addresss = msg.getRecipients(type); } if (addresss == null || addresss.length < 1) throw new MessagingException("û���ռ���!"); for (Address address : addresss) { InternetAddress internetAddress = (InternetAddress)address; receiveAddress.append(internetAddress.toUnicodeString()).append(","); } receiveAddress.deleteCharAt(receiveAddress.length()-1); //ɾ�����һ������ return receiveAddress.toString(); }
Example 5
Source File: MailProcessor.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private static Message.RecipientType parseType( final String type ) { if ( "TO".equalsIgnoreCase( type ) ) { return MimeMessage.RecipientType.TO; } if ( "CC".equalsIgnoreCase( type ) ) { return MimeMessage.RecipientType.CC; } if ( "BCC".equalsIgnoreCase( type ) ) { return MimeMessage.RecipientType.BCC; } return MimeMessage.RecipientType.TO; }
Example 6
Source File: MimeMessageBuilder.java From logging-log4j2 with Apache License 2.0 | 5 votes |
public MimeMessageBuilder setRecipients(final Message.RecipientType recipientType, final String recipients) throws MessagingException { final InternetAddress[] addresses = parseAddresses(recipients); if (null != addresses) { message.setRecipients(recipientType, addresses); } return this; }
Example 7
Source File: SearchTermBuilder.java From greenmail with Apache License 2.0 | 5 votes |
private static SearchTermBuilder createRecipientSearchTermBuilder(final Message.RecipientType type) { return new SearchTermBuilder() { @Override public SearchTerm build() { try { return new RecipientTerm(type, new InternetAddress(getParameters().get(0))); } catch (AddressException e) { throw new IllegalArgumentException("Address is not correct", e); } } }; }
Example 8
Source File: MailService.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
private void addRecipients(Email email, String name, String address, Message.RecipientType mailType) { if (! StringUtil.isNullOrEmpty(address)) { if (name == null) name = ""; email.addRecipients(name, mailType, address); } }
Example 9
Source File: SmtpOutputOperator.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
private void resetMessage() { if (!setupCalled) { return; } try { message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); for (Map.Entry<String, String> entry : recipients.entrySet()) { RecipientType type = RecipientType.valueOf(entry.getKey().toUpperCase()); Message.RecipientType recipientType; switch (type) { case TO: recipientType = Message.RecipientType.TO; break; case CC: recipientType = Message.RecipientType.CC; break; case BCC: default: recipientType = Message.RecipientType.BCC; break; } String[] addresses = entry.getValue().split(","); for (String address : addresses) { message.addRecipient(recipientType, new InternetAddress(address)); } } message.setSubject(subject); LOG.debug("all recipients {}", Arrays.toString(message.getAllRecipients())); } catch (MessagingException ex) { throw new RuntimeException(ex); } }
Example 10
Source File: EmailSender.java From cuba with Apache License 2.0 | 5 votes |
protected void assignRecipient(Message.RecipientType type, String addresses, MimeMessage message) throws MessagingException { if (StringUtils.isNotBlank(addresses)) { for (String address : splitAddresses(addresses)) { message.addRecipient(type, new InternetAddress(address.trim())); } } }
Example 11
Source File: SendReceiveWithInternationalAddressTest.java From greenmail with Apache License 2.0 | 5 votes |
private String getHeaderName(Message.RecipientType type) throws MessagingException { String headerName; if (type == Message.RecipientType.TO) headerName = "To"; else if (type == Message.RecipientType.CC) headerName = "Cc"; else if (type == Message.RecipientType.BCC) headerName = "Bcc"; else throw new MessagingException("Invalid Recipient Type"); return headerName; }
Example 12
Source File: HeaderExtractor.java From james-project with Apache License 2.0 | 4 votes |
static HeaderExtractor recipientExtractor(Message.RecipientType type) { String headerName = type.toString(); ThrowingFunction<Mail, String[]> addressGetter = mail -> mail.getMessage().getHeader(headerName); return addressExtractor(addressGetter, headerName); }
Example 13
Source File: MimeMessageCopyOnWriteProxy.java From james-project with Apache License 2.0 | 4 votes |
@Override public Address[] getRecipients(Message.RecipientType type) throws MessagingException { return getWrappedMessage().getRecipients(type); }
Example 14
Source File: MimeMessageCopyOnWriteProxy.java From james-project with Apache License 2.0 | 4 votes |
@Override public void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException { getWrappedMessageForWriting().setRecipients(type, addresses); }
Example 15
Source File: MimeMessageCopyOnWriteProxy.java From james-project with Apache License 2.0 | 4 votes |
@Override public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException { getWrappedMessageForWriting().addRecipients(type, addresses); }
Example 16
Source File: MimeMessageCopyOnWriteProxy.java From james-project with Apache License 2.0 | 4 votes |
@Override public void addRecipients(Message.RecipientType type, String addresses) throws MessagingException { getWrappedMessageForWriting().addRecipients(type, addresses); }
Example 17
Source File: MimeMessageCopyOnWriteProxy.java From james-project with Apache License 2.0 | 4 votes |
@Override public void setRecipients(Message.RecipientType type, String addresses) throws MessagingException { getWrappedMessageForWriting().setRecipients(type, addresses); }
Example 18
Source File: RecipientTerm.java From FairEmail with GNU General Public License v3.0 | 2 votes |
/** * Constructor. * * @param type the recipient type * @param address the address to match for */ public RecipientTerm(Message.RecipientType type, Address address) { super(address); this.type = type; }
Example 19
Source File: RecipientStringTerm.java From FairEmail with GNU General Public License v3.0 | 2 votes |
/** * Return the type of recipient to match with. * * @return the recipient type */ public Message.RecipientType getRecipientType() { return type; }
Example 20
Source File: RecipientStringTerm.java From FairEmail with GNU General Public License v3.0 | 2 votes |
/** * Constructor. * * @param type the recipient type * @param pattern the address pattern to be compared. */ public RecipientStringTerm(Message.RecipientType type, String pattern) { super(pattern); this.type = type; }