當前位置: 首頁>>代碼示例>>Java>>正文


Java AddressException.getMessage方法代碼示例

本文整理匯總了Java中javax.mail.internet.AddressException.getMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java AddressException.getMessage方法的具體用法?Java AddressException.getMessage怎麽用?Java AddressException.getMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.internet.AddressException的用法示例。


在下文中一共展示了AddressException.getMessage方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validateEmail

import javax.mail.internet.AddressException; //導入方法依賴的package包/類
/**
 * Validates an email
 *
 * @param email text entered
 * @return error message or null
 */
public static String validateEmail(String email) {
    String result = null;
    if (email.indexOf('@') < 0) {
        result = "Missing the @ character";
    }
    if (result == null) {
        try {
            InternetAddress emailAddr = new InternetAddress(email);
            emailAddr.validate();
        } catch (AddressException ex) {
            result = ex.getMessage();
        }
    }
    return result;
}
 
開發者ID:tim-lebedkov,項目名稱:npackd-gae-web,代碼行數:22,代碼來源:NWUtils.java

示例2: GMailClient

import javax.mail.internet.AddressException; //導入方法依賴的package包/類
GMailClient(Properties mailProperties) {
    final String username = mailProperties.getProperty("mail.smtp.username");
    final String password = mailProperties.getProperty("mail.smtp.password");

    log.info("Initializing gmail smtp mail transport. Username : {}. SMTP host : {}:{}",
            username, mailProperties.getProperty("mail.smtp.host"), mailProperties.getProperty("mail.smtp.port"));

    this.session = Session.getInstance(mailProperties, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });
    try {
        this.from = new InternetAddress(username);
    } catch (AddressException e) {
        throw new RuntimeException("Error initializing MailWrapper." + e.getMessage());
    }
}
 
開發者ID:blynkkk,項目名稱:blynk-server,代碼行數:19,代碼來源:GMailClient.java

示例3: setAsText

import javax.mail.internet.AddressException; //導入方法依賴的package包/類
@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);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:InternetAddressEditor.java

示例4: prepareAddress

import javax.mail.internet.AddressException; //導入方法依賴的package包/類
private InternetAddress prepareAddress(final String address) {
    try {
        return new InternetAddress(address);
    } catch (AddressException e) {
        throw new IWSException(IWSErrors.ERROR, "Invalid Internet Address: " + e.getMessage(), e);
    }
}
 
開發者ID:IWSDevelopers,項目名稱:iws,代碼行數:8,代碼來源:EmailSender.java

示例5: sendEmails

import javax.mail.internet.AddressException; //導入方法依賴的package包/類
/**
 * Handle the actual sending of the email
 * @param fromAddress
 * @param toEmails
 * @param subject
 * @param message
 * @param deferExceptions
 * @param exceptionTracker
 * @return an array of all email addresses that were sent to
 */
private String[] sendEmails(InternetAddress fromAddress, List<String> toEmails, String subject,
        String message, boolean deferExceptions, String exceptionTracker) {
    InternetAddress[] replyTo = new InternetAddress[1];
    List<InternetAddress> listAddresses = new ArrayList<>();
    for (int i = 0; i < toEmails.size(); i++) {
        String email = toEmails.get(i);
        try {
            InternetAddress toAddress = new InternetAddress(email);
            listAddresses.add(toAddress);
        } catch (AddressException e) {
            if (deferExceptions) {
                exceptionTracker += e.getMessage() + " :: ";
                LOG.debug("Invalid to address (" + email + "), skipping it, error:("+e+")...");
                if (LOG.isDebugEnabled()) {
                    LOG.warn( e );
                }
            } else {
                // die here since we were unable to find this user at all
                throw new IllegalArgumentException("Invalid to address: " + email + ", cannot send emails", e);
            } 
        }
    }
    replyTo[0] = fromAddress;
    InternetAddress[] toAddresses = listAddresses.toArray(new InternetAddress[listAddresses.size()]);
    // headers are set globally and used for all emails going out (see top of this file)
    // added to ensure non-blank TO header: http://bugs.sakaiproject.org/jira/browse/EVALSYS-724
    emailService.sendMail(fromAddress, toAddresses, subject, message, 
            new InternetAddress[]{fromAddress}, replyTo, this.emailHeaders);

    if (deferExceptions && exceptionTracker != null) {
        // exceptions occurred so we have to die here
        throw new IllegalArgumentException("The following exceptions were deferred (full trace above in the log): " + 
                "Sent emails to " + toAddresses.length + " addresses before failure ocurred: Failure summary: " +
                exceptionTracker);
    }

    // now we send back the list of people who the email was sent to
    String[] addresses = new String[toAddresses.length];
    for (int i = 0; i < toAddresses.length; i++) {
        addresses[i] = toAddresses[i].getAddress();
    }
    return addresses;
}
 
開發者ID:sakaicontrib,項目名稱:evaluation,代碼行數:54,代碼來源:EvalExternalLogicImpl.java


注:本文中的javax.mail.internet.AddressException.getMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。