Search in sources :

Example 1 with AMSendMail

use of com.iplanet.am.util.AMSendMail in project OpenAM by OpenRock.

the class DefaultSMSGatewayImpl method sendSMSMessage.

/**
     * {@inheritDoc}
     */
public void sendSMSMessage(String from, String to, String subject, String message, String code, Map options) throws AuthLoginException {
    if (to == null) {
        return;
    }
    try {
        setOptions(options);
        String msg = message + code;
        String[] tos = new String[1];
        // <phone@provider_address). For exampe : 4080989109@txt.att.net
        if (to.indexOf("@") == -1) {
            to = to + "@txt.att.net";
        }
        tos[0] = to;
        AMSendMail sendMail = new AMSendMail();
        if (smtpHostName == null || smtpHostPort == null) {
            sendMail.postMail(tos, subject, msg, from);
        } else {
            sendMail.postMail(tos, subject, msg, from, "UTF-8", smtpHostName, smtpHostPort, smtpUserName, smtpUserPassword, sslEnabled);
        }
        if (debug.messageEnabled()) {
            debug.message("DefaultSMSGatewayImpl.sendSMSMessage() : " + "HOTP sent to : " + to + ".");
        }
    } catch (Exception e) {
        debug.error("DefaultSMSGatewayImpl.sendSMSMessage() : " + "Exception in sending HOTP code : ", e);
        throw new AuthLoginException("Failed to send OTP code to " + to, e);
    }
}
Also used : AMSendMail(com.iplanet.am.util.AMSendMail) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException)

Example 2 with AMSendMail

use of com.iplanet.am.util.AMSendMail in project OpenAM by OpenRock.

the class EmailPassword method sendEmailToUser.

/**
     * Sents reset password email to the user.
     *
     * @param emailAddres email address of the user
     * @param password new password
     */
private void sendEmailToUser(String emailAddress, String password) throws MessagingException {
    String[] obj = new String[1];
    obj[0] = password;
    ResourceBundle rb = PWResetResBundleCacher.getBundle(bundleName, userLocale);
    String msg = MessageFormat.format(rb.getString("resetPassMail.message"), (Object[]) obj);
    String subject = rb.getString("resetSubject.message");
    String[] to = new String[1];
    to[0] = emailAddress;
    String from = rb.getString("fromAddress.label");
    String charset = g11nSettings.getDefaultCharsetForLocale(userLocale);
    AMSendMail sendMail = new AMSendMail();
    sendMail.postMail(to, subject, msg, from, charset);
}
Also used : AMSendMail(com.iplanet.am.util.AMSendMail) ResourceBundle(java.util.ResourceBundle)

Example 3 with AMSendMail

use of com.iplanet.am.util.AMSendMail in project OpenAM by OpenRock.

the class DefaultEmailGatewayImpl method sendEmail.

/**
    * Sends an email  message to the mail with the code
    * <p>
    *
    * @param from The address that sends the E-mail message
    * @param to The address that the E-mail message is sent
    * @param subject The E-mail subject
    * @param message The content contained in the E-mail message
    * @param options The outbound SMTP gateway
    * module
    */
public void sendEmail(String from, String to, String subject, String message, Map<String, String> options) throws NoEmailSentException {
    if (to == null) {
        if (debug.messageEnabled()) {
            debug.message("DefaultEmailGatewayImpl::sendEmail to header is empty");
        }
        return;
    }
    try {
        setOptions(options);
        String[] tos = new String[] { to };
        AMSendMail sendMail = new AMSendMail();
        if (smtpHostName == null || smtpHostPort == null || smtpUserName == null || smtpUserPassword == null || smtpSSLEnabled == null) {
            sendMail.postMail(tos, subject, message, from);
            OAuthUtil.debugWarning("DefaultEmailGatewayImpl.sendEmail() :" + "sending email using the defaults localhost and port 25");
        } else {
            sendMail.postMail(tos, subject, message, from, "UTF-8", smtpHostName, smtpHostPort, smtpUserName, smtpUserPassword, sslEnabled);
        }
        OAuthUtil.debugMessage("DefaultEmailGatewayImpl.sendEmail() : " + "email sent to : " + to + ".");
    } catch (Exception ex) {
        debug.error("DefaultEmailGatewayImpl.sendEmail() : " + "Exception in sending email : ", ex);
        throw new NoEmailSentException(ex);
    }
}
Also used : AMSendMail(com.iplanet.am.util.AMSendMail)

Example 4 with AMSendMail

use of com.iplanet.am.util.AMSendMail in project OpenAM by OpenRock.

the class ISAccountLockout method sendLockOutNotice.

/**
     * Sends (Email) the lockout notice to the email address
     * specified in the lockout notification attribute with
     * the userDN information of the user whose account is
     * locked.
     *
     * @param userDN Distinguished name of the user
     */
public void sendLockOutNotice(String userDN) {
    if (lockoutNotification != null) {
        AMSendMail sm = new AMSendMail();
        StringTokenizer emailTokens = new StringTokenizer(lockoutNotification, SPACE_DELIM);
        while (emailTokens.hasMoreTokens()) {
            StringTokenizer stz2 = new StringTokenizer(emailTokens.nextToken(), PIPE_DELIM);
            String[] toAddress = { stz2.nextToken() };
            String locale = null;
            String charset = null;
            if (stz2.hasMoreTokens()) {
                locale = stz2.nextToken();
                if (stz2.hasMoreTokens()) {
                    charset = stz2.nextToken();
                }
            }
            ResourceBundle rb = com.sun.identity.shared.locale.Locale.getResourceBundle(bundleName, locale);
            String fromAddress = rb.getString(FROM_ADDRESS);
            String emailSubject = rb.getString(EMAIL_SUBJECT);
            String[] obj = { userDN };
            String emailMsg = MessageFormat.format(rb.getString(EMAIL_MESSAGE), (Object[]) obj);
            if (debug.messageEnabled()) {
                debug.message("ISAccountLockout.sendLockOutNotice:" + " lockoutNotification = " + lockoutNotification + " toAddress = " + toAddress);
            }
            try {
                sm.postMail(toAddress, emailSubject, emailMsg, fromAddress, charset);
            } catch (MessagingException ex) {
                debug.error("cannot email lockout notification:token ", ex);
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) MessagingException(javax.mail.MessagingException) AMSendMail(com.iplanet.am.util.AMSendMail) ResourceBundle(java.util.ResourceBundle)

Aggregations

AMSendMail (com.iplanet.am.util.AMSendMail)4 ResourceBundle (java.util.ResourceBundle)2 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 StringTokenizer (java.util.StringTokenizer)1 MessagingException (javax.mail.MessagingException)1