Example usage for org.apache.commons.mail Email setAuthenticator

List of usage examples for org.apache.commons.mail Email setAuthenticator

Introduction

In this page you can find the example usage for org.apache.commons.mail Email setAuthenticator.

Prototype

public void setAuthenticator(final Authenticator newAuthenticator) 

Source Link

Document

Sets the Authenticator to be used when authentication is requested from the mail server.

Usage

From source file:edu.corgi.uco.sendEmails.java

public static void sendStudentConfirmation(String fn, String ln, Date date, String email2) {

    try {/*w  ww .  j  ava2s.co m*/
        System.out.print("hit send");
        Email email = new SimpleEmail();
        System.out.print("created email file");
        email.setDebug(true);
        email.setHostName("smtp.gmail.com");
        email.setAuthenticator(new DefaultAuthenticator("ucocorgi2@gmail.com", "ucodrsung"));
        email.setStartTLSEnabled(true);
        email.setSmtpPort(587);
        email.setFrom("ucocorgi@gmail.com", "UCO Advisement");
        email.setSubject("Advisement Update");
        email.setMsg(fn + " " + ln + ", you have signed up for an advisement appointment at " + date
                + ". It is recommended that you use the Corgi system to define your "
                + "preferred schedule for next semester prior to your meeting.");

        System.out.print("Email Address: ucocorgi@gmail.com");
        email.addTo(email2);

        System.out.print("added values");

        email.send();
        System.out.print("sent");
    } catch (EmailException ex) {
        Logger.getLogger(sendEmails.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:de.maklerpoint.office.Schnittstellen.Email.SimpleEmailSender.java

/**
 * // w w w .j a  v a2s  .co m
 * @param adress
 * @param Subject
 * @param body
 * @throws EmailException 
 */

public static void sendSimpleEMail(String adress, String Subject, String body) throws EmailException {
    Email email = new SimpleEmail();
    email.setHostName(Config.get("mailHost", ""));
    email.setSmtpPort(Config.getConfigInt("emailPort", 25));

    email.setTLS(Config.getConfigBoolean("mailTLS", false));
    email.setSSL(Config.getConfigBoolean("mailSSL", false));

    //email.setSslSmtpPort(Config.getConfigInt("emailPort", 25));
    email.setAuthenticator(
            new DefaultAuthenticator(Config.get("mailUsername", ""), Config.get("mailPassword", "")));

    email.setFrom(Config.get("mailSendermail", ""), Config.get("mailSender", ""));

    email.setSubject(Subject);
    email.setMsg(body);
    email.addTo(adress);

    email.send();
}

From source file:FacultyAdvisement.StudentRepository.java

public static void adminUpdate(DataSource ds, Student student, String oldUsername) throws SQLException {
    Connection conn = ds.getConnection();
    if (conn == null) {
        throw new SQLException("conn is null; Can't get db connection");
    }/*from w w  w .  j a v a2  s.  c o  m*/
    try {

        PreparedStatement ps;
        ps = conn.prepareStatement(
                "Update STUDENT set EMAIL=?, FIRSTNAME=?, LASTNAME=?, MAJORCODE=?, PHONE=?, ADVISED=? where STUID=?");
        ps.setString(1, student.getUsername());
        ps.setString(2, student.getFirstName());
        ps.setString(3, student.getLastName());
        ps.setString(4, student.getMajorCode());
        ps.setString(5, student.getPhoneNumber());
        if (student.isAdvised()) {
            ps.setString(6, "true");
        } else {
            ps.setString(6, "false");
        }
        ps.setString(7, student.getId());
        ps.executeUpdate();

        ps = conn.prepareStatement("Update USERTABLE set USERNAME=? where USERNAME=?");
        ps.setString(1, student.getUsername());
        ps.setString(2, oldUsername);
        ps.executeUpdate();

        ps = conn.prepareStatement("Update GROUPTABLE set USERNAME=? where USERNAME=?");
        ps.setString(1, student.getUsername());
        ps.setString(2, oldUsername);
        ps.executeUpdate();

        if (student.isResetPassword()) {
            String newPassword = UUID.randomUUID().toString();
            String encryptedPassword = SHA256Encrypt.encrypt(newPassword);
            ps = conn.prepareStatement("Update USERTABLE set PASSWORD=? where USERNAME=?");
            ps.setString(1, encryptedPassword);
            ps.setString(2, student.getUsername());
            ps.executeUpdate();

            Email email = new HtmlEmail();
            email.setHostName("smtp.googlemail.com");
            email.setSmtpPort(465);
            email.setAuthenticator(new DefaultAuthenticator("uco.faculty.advisement", "!@#$1234"));
            email.setSSLOnConnect(true);
            email.setFrom("uco.faculty.advisement@gmail.com");
            email.setSubject("UCO Faculty Advisement Password Change");
            email.setMsg("<font size=\"3\">An admin has resetted your password, your new password is \""
                    + newPassword + "\"." + "\n<p align=\"center\">UCO Faculty Advisement</p></font>");
            email.addTo(student.getUsername());
            email.send();

        }

    } catch (EmailException ex) {
        Logger.getLogger(StudentRepository.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        conn.close();
    }

    //students = (HashMap<String, StudentPOJO>) readAll(); // reload the updated info
}

From source file:br.com.recursive.biblioteca.servicos.EmailService.java

public void sendHtmlEmail(Pessoa pessoa) throws EmailException {

    Email email = new HtmlEmail();
    email.setAuthenticator(new DefaultAuthenticator("claupwd@gmail.com", "@claupwd2014"));
    email.setHostName("smtp.gmail.com");
    email.setFrom("claupwd@gmail.com");
    email.setSubject("SIB Online - Recuperao de Senha");
    email.setMsg(createMessage(pessoa));
    email.addTo(pessoa.getContato().getEmail());
    email.setSSL(true);/*from  ww w. ja v a  2 s  .c o m*/
    //Se true, exibe na saida todo o processo do envio do email
    email.setDebug(true);
    email.send();
}

From source file:br.com.jvmsoftware.util.EnviarMail.java

public void emailSimples(PubConfigEmpresa conf, PubUsuario usu, String msg, String subj) throws EmailException {

    Email email = new SimpleEmail();
    email.setHostName(conf.getMailEnvioSmtp());
    email.setSmtpPort(conf.getMailEnvioPorta());
    email.setAuthenticator(new DefaultAuthenticator(conf.getMailEnvio(), conf.getMailEnvioSenha()));
    email.setSSLOnConnect(true);/*from ww w .j a  v a  2  s  .  co  m*/
    email.setFrom(conf.getMailEnvio());
    email.setSubject(subj);
    email.setMsg(msg);
    email.addTo(usu.getEmail());
    email.send();
}

From source file:com.cognifide.qa.bb.email.EmailSender.java

public void sendEmail(final EmailData emailData) {
    try {/*from  ww  w .  j a  v a 2 s . co m*/
        Email email = new SimpleEmail();
        email.setHostName(smtpServer);
        email.setSmtpPort(smtpPort);
        email.setAuthenticator(new DefaultAuthenticator(username, password));
        email.setSSLOnConnect(secure);
        email.setFrom(emailData.getAddressFrom());
        email.setSubject(emailData.getSubject());
        email.setMsg(emailData.getMessageContent());
        email.addTo(emailData.getAddressTo());
        email.send();
    } catch (org.apache.commons.mail.EmailException e) {
        throw new EmailException(e);
    }
}

From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java

/**
 * Sends a password reset email to the email address provided
 * /*  ww  w .  j av  a  2s.c  o  m*/
 * @param toEmail
 * @param newPwd
 * @throws Exception
 */
public void sendPwdResetMailFromApp(String toEmail, String newPwd) throws Exception {
    Email email = new SimpleEmail();
    email.setSmtpPort(Integer.parseInt(smtpPort));
    email.setAuthenticator(new DefaultAuthenticator(fromAddress, fromPwd));
    email.setDebug(Boolean.parseBoolean(debugEnabled));
    email.setHostName(smtpSever);
    email.setFrom(fromAddress);
    email.setSubject("Reset Olhie Password");
    email.setMsg("You have requested that your password be reset. Your new Olhie password is " + newPwd);
    email.addTo(toEmail);
    email.setTLS(Boolean.parseBoolean(tlsEnabled));
    email.setSocketTimeout(10000);
    email.setSocketConnectionTimeout(12000);
    email.send();
}

From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java

/**
 * Author Request email that goes to the olhie administrator
 * /*w  w w  . j ava 2  s  .  c o m*/
 * @param toEmail
 * @param userId
 * @param firstName
 * @param lastName
 * @param regId
 * @throws Exception
 */
public void sendRequestAuthorMailFromApp(String toEmail, String userId, String firstName, String lastName,
        String regId) throws Exception {
    Email email = new SimpleEmail();
    email.setSmtpPort(Integer.parseInt(smtpPort));
    email.setAuthenticator(new DefaultAuthenticator(fromAddress, fromPwd));
    email.setDebug(Boolean.parseBoolean(debugEnabled));
    email.setHostName(smtpSever);
    email.setFrom(fromAddress);
    email.setSubject("Author Request");
    email.setMsg("User Id: " + userId + " Name: " + firstName + " " + lastName + " Registration Id: " + regId);
    email.addTo(toEmail);
    email.setTLS(Boolean.parseBoolean(tlsEnabled));
    email.setSocketTimeout(10000);
    email.setSocketConnectionTimeout(12000);
    email.send();
}

From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java

/**
 * @param toEmail/* ww w . j a va2s . c  o  m*/
 * @param userId
 * @param firstName
 * @param lastName
 * @param eventId
 * @param details
 * @throws Exception
 */
public void sendRequestMailForCalendarEventFromApp(String toEmail, String userId, String firstName,
        String lastName, String eventId, String details) throws Exception {
    Email email = new SimpleEmail();
    email.setSmtpPort(Integer.parseInt(smtpPort));
    email.setAuthenticator(new DefaultAuthenticator(fromAddress, fromPwd));
    email.setDebug(Boolean.parseBoolean(debugEnabled));
    email.setHostName(smtpSever);
    email.setFrom(fromAddress);
    email.setSubject("Calendar Event Request");
    email.setMsg("User Id: " + userId + " Name: " + firstName + " " + lastName + " Event Id: " + eventId + "\n"
            + details);
    email.addTo(toEmail);
    email.setTLS(Boolean.parseBoolean(tlsEnabled));
    email.setSocketTimeout(10000);
    email.setSocketConnectionTimeout(12000);
    email.send();
}

From source file:beanView.MbVListaEmail.java

public void sendMail() {
    String subject = nombre + " " + eMail;
    try {//from  w w  w . ja va2  s  .co  m

        Email email = new SimpleEmail();
        email.setHostName("smtp.gmail.com");
        email.setSmtpPort(465);
        email.setAuthenticator(new DefaultAuthenticator("altabar.listas", "Nivde017"));
        email.setSSLOnConnect(true);
        email.isStartTLSEnabled();
        email.setFrom("altabar.listas@gmail.com");
        email.setSubject(subject);
        email.setMsg(message);
        email.addTo("eacunagon@gmail.com");
        email.send();
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_INFO, "Listo!", "Lista enviada"));
    } catch (Exception ex) {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", ex.getMessage()));
        eMail = "";
        nombre = "";
        message = "";

    }

}