Example usage for javax.mail.internet InternetAddress validate

List of usage examples for javax.mail.internet InternetAddress validate

Introduction

In this page you can find the example usage for javax.mail.internet InternetAddress validate.

Prototype

public void validate() throws AddressException 

Source Link

Document

Validate that this address conforms to the syntax rules of RFC 822.

Usage

From source file:com.mycollab.core.utils.StringUtils.java

public static boolean isValidEmail(String value) {
    try {//from  ww  w  .  j  a  v  a 2 s.  c o  m
        //
        // Create InternetAddress object and validated the supplied
        // address which is this case is an email address.
        InternetAddress internetAddress = new InternetAddress(value);
        internetAddress.validate();
        return true;
    } catch (AddressException e) {
        return false;
    }
}

From source file:azkaban.reportal.util.ReportalHelper.java

/**
 * Returns true if the given email is valid and false otherwise.
 * @param email/*from   www  .  j  av  a2s.c o m*/
 * @return
 */
public static boolean isValidEmailAddress(String email) {
    if (email == null) {
        return false;
    }

    boolean result = true;
    try {
        InternetAddress emailAddr = new InternetAddress(email);
        emailAddr.validate();
    } catch (AddressException ex) {
        result = false;
    }
    return result;
}

From source file:io.stallion.utils.GeneralUtils.java

public static boolean isValidEmailAddress(String email) {
    boolean result = true;
    try {/* w  ww .j  a va2  s  .  co m*/
        InternetAddress emailAddr = new InternetAddress(email);
        emailAddr.validate();
    } catch (AddressException ex) {
        result = false;
    }
    return result;
}

From source file:nc.noumea.mairie.appock.core.utility.AppockUtil.java

public static boolean isValidEmailAddress(String email) {
    if (StringUtils.isBlank(email)) {
        return false;
    }// ww  w  . ja v  a2  s.co  m
    boolean result = true;
    try {
        InternetAddress emailAddr = new InternetAddress(email);
        emailAddr.validate();
    } catch (AddressException ex) {
        result = false;
    }
    return result;
}

From source file:org.openmhealth.reference.domain.User.java

/**
 * Verifies that an email address is a valid email address, but it does not
 * guarantee that the location that it references exists.
 * //  w ww.ja v a  2  s.  co  m
 * @param email
 *        The email address to be validated.
 * 
 * @return The email address as an InternetAddress object.
 * 
 * @throws OmhException
 *         The email address is invalid.
 */
public static InternetAddress validateEmail(final String email) throws OmhException {

    if (email == null) {
        throw new OmhException("The email address is null");
    }
    String trimmedEmail = email.trim();
    if (trimmedEmail.length() == 0) {
        throw new OmhException("The email address is empty.");
    }

    // Create the InternetAddress object.
    InternetAddress result;
    try {
        result = new InternetAddress(email);
    } catch (AddressException e) {
        throw new OmhException("The email address is not a valid email address.", e);
    }

    // Validate the address.
    try {
        result.validate();
    } catch (AddressException e) {
        throw new OmhException("The email address is not a valid email address.", e);
    }

    return result;
}

From source file:controllers.Send.java

public static Result sendTransactionViaEmail(String id, String recipient) {
    // Send email
    //      models.Customer sender = models.Customer.find.byId(transactionForm.get().sender.id);

    Logger.debug("Tyrying to send transaction to " + recipient);
    if (recipient == null) {
        // TODO get from beneficiary email
        flash("error", "Unidentified sender email");
    }//  www. ja  v  a  2  s .  c o m

    try {
        JsonNode result = ApiHelper.transactionDetail(id);
        Html html = receipt_email.render(result);

        InternetAddress[] tos = InternetAddress.parse(recipient);
        if ((tos.length > 0)) {
            InternetAddress to = tos[0];
            to.validate();
            //TODO Check if valid
            ApiHelper.sendHtmlEmail(null, tos[0], "Bukti transaksi pengiriman uang", html);
            flash("success", "Transaction email has been sent to sender email <strong>"
                    + recipient.replaceAll("<", "(").replaceAll(">", ")") + "</strong>");
        } else {
            //            flash("error", "Unable to send email to "+recipient);
        }
    } catch (EmailException e) {
        e.printStackTrace();
        Logger.error(e.getMessage(), e);
        flash("error", "Unable to send email to " + recipient);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        Logger.error(e.getMessage(), e);
        flash("error", "Unable to send email to " + recipient);
    } catch (AddressException e) {
        e.printStackTrace();
        Logger.error(e.getMessage(), e);
        flash("error", "Unable to send email to " + recipient);
    }

    return redirect(routes.Send.receipt(id));
}

From source file:org.apache.fineract.infrastructure.scheduledemail.service.EmailCampaignWritePlatformCommandHandlerImpl.java

public static boolean isValidEmail(String email) {

    boolean isValid = true;

    try {// w ww  .j  a  va 2  s .com

        InternetAddress emailO = new InternetAddress(email);
        emailO.validate();

    } catch (AddressException ex) {

        isValid = false;
    }
    return isValid;
}

From source file:org.gbif.ipt.validation.BaseValidator.java

protected boolean isValidEmail(String email) {
    if (email != null) {
        try {/* w  w w.jav a  2 s .c  o  m*/
            InternetAddress internetAddress = new InternetAddress(email);
            internetAddress.validate();
            return true;
        } catch (javax.mail.internet.AddressException e) {
            LOG.debug("Email address was invalid: " + Strings.nullToEmpty(email));
        }
    }
    return false;
}

From source file:com.jaspersoft.jasperserver.core.util.validators.EmailInputValidator.java

@Override
public boolean isValid(T email) {
    if (email == null) {
        return false;
    }/*from  w  w w .  j a  v a2s . c  om*/

    if (this.getPattern() != null) {
        return super.isValid(email);

    } else {
        boolean result = true;
        try {
            InternetAddress emailAddress = new InternetAddress(email.toString());
            emailAddress.validate();
        } catch (AddressException ex) {
            result = false;
            if (log.isDebugEnabled()) {
                log.debug(String.format("Email address %s not valid.", email));
            }
        }

        return result;
    }
}

From source file:org.jasig.schedassist.impl.reminder.DefaultEmailAddressValidatorImpl.java

@Override
public boolean canSendToEmailAddress(ICalendarAccount account) {
    if (account == null) {
        return false;
    }//from   w  ww  . j a v a2 s  . co m

    final String address = account.getEmailAddress();
    if (StringUtils.isBlank(address)) {
        return false;
    }

    try {
        InternetAddress emailAddr = new InternetAddress(address);
        emailAddr.validate();
        String[] parts = address.split("@");
        if (parts.length == 2) {
            if (!restrictedDomains.contains(parts[1])) {
                return true;
            }
        }
    } catch (AddressException ex) {
        log.info("email address for " + account + " failed to valdidate", ex);
        return false;
    }

    return false;
}