public static boolean isValidEmailAddress(String email) { boolean result = true; try { InternetAddress emailAddr = new InternetAddress(email); emailAddr.validate(); } catch (AddressException ex) { result = false; } return result; }
/** * Set the sent-date of the message. * @param sentDate the date to set (never {@code null}) * @throws MessagingException in case of errors */ public void setSentDate(Date sentDate) throws MessagingException { Assert.notNull(sentDate, "Sent date must not be null"); this.mimeMessage.setSentDate(sentDate); }
public static String encode(String value, String charset) { try { return MimeUtility.encodeText(value, charset, null); } catch (UnsupportedEncodingException ex) { throw new IllegalStateException(ex); } } }
private InternetAddress parseAddress(String address) throws MessagingException { InternetAddress[] parsed = InternetAddress.parse(address); if (parsed.length != 1) { throw new AddressException("Illegal address", address); } InternetAddress raw = parsed[0]; try { return (getEncoding() != null ? new InternetAddress(raw.getAddress(), raw.getPersonal(), getEncoding()) : raw); } catch (UnsupportedEncodingException ex) { throw new MessagingException("Failed to parse embedded personal name to correct encoding", ex); } }
@Override public void prepare(MimeMessage mimeMessage) throws MessagingException { mimeMessage.setFrom(new InternetAddress("")); } };
@Override public void prepare(MimeMessage mimeMessage) throws MessagingException { mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("she@mail.org")); messages.add(mimeMessage); } };
public FormValidation doCheckAdminAddress(@QueryParameter String value) { try { new InternetAddress(value); return FormValidation.ok(); } catch (AddressException e) { return FormValidation.error(e.getMessage()); } }
private MimeBodyPart getMainPart() throws MessagingException { MimeMultipart mimeMultipart = getMimeMultipart(); MimeBodyPart bodyPart = null; for (int i = 0; i < mimeMultipart.getCount(); i++) { BodyPart bp = mimeMultipart.getBodyPart(i); if (bp.getFileName() == null) { bodyPart = (MimeBodyPart) bp; } } if (bodyPart == null) { MimeBodyPart mimeBodyPart = new MimeBodyPart(); mimeMultipart.addBodyPart(mimeBodyPart); bodyPart = mimeBodyPart; } return bodyPart; }
public void addTo(String to, String personal) throws MessagingException, UnsupportedEncodingException { Assert.notNull(to, "To address must not be null"); addTo(getEncoding() != null ? new InternetAddress(to, personal, getEncoding()) : new InternetAddress(to, personal)); }
@Override public MimeMessage createMimeMessage(InputStream contentStream) throws MailException { try { return new MimeMessage(getSession(), contentStream); } catch (Exception ex) { throw new MailParseException("Could not parse raw MIME content", ex); } }
public void addBcc(InternetAddress bcc) throws MessagingException { Assert.notNull(bcc, "Bcc address must not be null"); validateAddress(bcc); this.mimeMessage.addRecipient(Message.RecipientType.BCC, bcc); }
/** * Set the priority ("X-Priority" header) of the message. * @param priority the priority value; * typically between 1 (highest) and 5 (lowest) * @throws MessagingException in case of errors */ public void setPriority(int priority) throws MessagingException { this.mimeMessage.setHeader(HEADER_PRIORITY, Integer.toString(priority)); }
public static String decode(String value) { try { return MimeUtility.decodeText(value); } catch (UnsupportedEncodingException ex) { throw new IllegalStateException(ex); } } }
public void setTo(InternetAddress to) throws MessagingException { Assert.notNull(to, "To address must not be null"); validateAddress(to); this.mimeMessage.setRecipient(Message.RecipientType.TO, to); }
private void setHtmlTextToMimePart(MimePart mimePart, String text) throws MessagingException { if (getEncoding() != null) { mimePart.setContent(text, CONTENT_TYPE_HTML + CONTENT_TYPE_CHARSET_SUFFIX + getEncoding()); } else { mimePart.setContent(text, CONTENT_TYPE_HTML); } }
@Override public String getAsText() { InternetAddress value = (InternetAddress) getValue(); return (value != null ? value.toUnicodeString() : ""); }
@Override public void prepare(MimeMessage mimeMessage) throws MessagingException { mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("you@mail.org")); messages.add(mimeMessage); } };
@Override public void setAsText(String text) throws IllegalArgumentException { if (StringUtils.hasText(text)) { try { setValue(new InternetAddress(text)); } catch (AddressException ex) { throw new IllegalArgumentException("Could not parse mail address: " + ex.getMessage()); } } else { setValue(null); } }
@Override public void prepare(MimeMessage mimeMessage) throws MessagingException { mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("he@mail.org")); messages.add(mimeMessage); } };