@Test public void sendMessage_withMessageTooLarge_shouldThrow() throws Exception { Message message = getDefaultMessageBuilder() .setHasAttachments(true) .messageSize(1234L) .build(); MockSmtpServer server = createServerAndSetupForPlainAuthentication("SIZE 1000"); SmtpTransport transport = startServerAndCreateSmtpTransport(server); try { transport.sendMessage(message); fail("Expected message too large error"); } catch (MessagingException e) { assertTrue(e.isPermanentFailure()); assertEquals("Message too large for server", e.getMessage()); } }
@Override public void sendMessage(Message message) throws MessagingException { List<Address> addresses = new ArrayList<>(); { addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.TO))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.CC))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.BCC))); } message.setRecipients(RecipientType.BCC, null); Map<String, List<String>> charsetAddressesMap = new HashMap<>(); for (Address address : addresses) { String addressString = address.getAddress(); String charset = CharsetSupport.getCharsetFromAddress(addressString); List<String> addressesOfCharset = charsetAddressesMap.get(charset); if (addressesOfCharset == null) { addressesOfCharset = new ArrayList<>(); charsetAddressesMap.put(charset, addressesOfCharset); } addressesOfCharset.add(addressString); } for (Map.Entry<String, List<String>> charsetAddressesMapEntry : charsetAddressesMap.entrySet()) { String charset = charsetAddressesMapEntry.getKey(); List<String> addressesOfCharset = charsetAddressesMapEntry.getValue(); message.setCharset(charset); sendMessageTo(addressesOfCharset, message); } }
SmtpTransport extends Transport { @Override public void sendMessage(Message message) throws MessagingException { List<Address> addresses = new ArrayList<>(); { addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.TO))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.CC))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.BCC))); } message.setRecipients(RecipientType.BCC, null); Map<String, List<String>> charsetAddressesMap = new HashMap<>(); for (Address address : addresses) { String addressString = address.getAddress(); String charset = CharsetSupport.getCharsetFromAddress(addressString); List<String> addressesOfCharset = charsetAddressesMap.get(charset); if (addressesOfCharset == null) { addressesOfCharset = new ArrayList<>(); charsetAddressesMap.put(charset, addressesOfCharset); } addressesOfCharset.add(addressString); } for (Map.Entry<String, List<String>> charsetAddressesMapEntry : charsetAddressesMap.entrySet()) { String charset = charsetAddressesMapEntry.getKey(); List<String> addressesOfCharset = charsetAddressesMapEntry.getValue(); message.setCharset(charset); sendMessageTo(addressesOfCharset, message); } } }
SmtpTransport extends Transport { @Override public void sendMessage(Message message) throws MessagingException { List<Address> addresses = new ArrayList<>(); { addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.TO))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.CC))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.BCC))); } message.setRecipients(RecipientType.BCC, null); Map<String, List<String>> charsetAddressesMap = new HashMap<>(); for (Address address : addresses) { String addressString = address.getAddress(); String charset = CharsetSupport.getCharsetFromAddress(addressString); List<String> addressesOfCharset = charsetAddressesMap.get(charset); if (addressesOfCharset == null) { addressesOfCharset = new ArrayList<>(); charsetAddressesMap.put(charset, addressesOfCharset); } addressesOfCharset.add(addressString); } for (Map.Entry<String, List<String>> charsetAddressesMapEntry : charsetAddressesMap.entrySet()) { String charset = charsetAddressesMapEntry.getKey(); List<String> addressesOfCharset = charsetAddressesMapEntry.getValue(); message.setCharset(charset); sendMessageTo(addressesOfCharset, message); } } SmtpTransport(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
            OAuth2TokenProvider oauthTokenProvider); }
SmtpTransport extends Transport { @Override public void sendMessage(Message message) throws MessagingException { List<Address> addresses = new ArrayList<>(); { addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.TO))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.CC))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.BCC))); } message.setRecipients(RecipientType.BCC, null); Map<String, List<String>> charsetAddressesMap = new HashMap<>(); for (Address address : addresses) { String addressString = address.getAddress(); String charset = CharsetSupport.getCharsetFromAddress(addressString); List<String> addressesOfCharset = charsetAddressesMap.get(charset); if (addressesOfCharset == null) { addressesOfCharset = new ArrayList<>(); charsetAddressesMap.put(charset, addressesOfCharset); } addressesOfCharset.add(addressString); } for (Map.Entry<String, List<String>> charsetAddressesMapEntry : charsetAddressesMap.entrySet()) { String charset = charsetAddressesMapEntry.getKey(); List<String> addressesOfCharset = charsetAddressesMapEntry.getValue(); message.setCharset(charset); sendMessageTo(addressesOfCharset, message); } } SmtpTransport(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
            OAuth2TokenProvider oauthTokenProvider); @Override void open(); @Override void sendMessage(Message message); @Override void close(); }
SmtpTransport extends Transport { @Override public void sendMessage(Message message) throws MessagingException { List<Address> addresses = new ArrayList<>(); { addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.TO))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.CC))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.BCC))); } message.setRecipients(RecipientType.BCC, null); Map<String, List<String>> charsetAddressesMap = new HashMap<>(); for (Address address : addresses) { String addressString = address.getAddress(); String charset = CharsetSupport.getCharsetFromAddress(addressString); List<String> addressesOfCharset = charsetAddressesMap.get(charset); if (addressesOfCharset == null) { addressesOfCharset = new ArrayList<>(); charsetAddressesMap.put(charset, addressesOfCharset); } addressesOfCharset.add(addressString); } for (Map.Entry<String, List<String>> charsetAddressesMapEntry : charsetAddressesMap.entrySet()) { String charset = charsetAddressesMapEntry.getKey(); List<String> addressesOfCharset = charsetAddressesMapEntry.getValue(); message.setCharset(charset); sendMessageTo(addressesOfCharset, message); } } SmtpTransport(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
            OAuth2TokenProvider oauthTokenProvider); @Override void open(); @Override void sendMessage(Message message); @Override void close();  }