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

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

Introduction

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

Prototype

public void setSmtpPort(final int aPortNumber) 

Source Link

Document

Set the port number of the outgoing mail server.

Usage

From source file:ar.com.pahema.utils.MailSender.java

public static void enviar(String destino, Paquete paquete) throws EmailException {
    try {//  w w w  .j av  a  2  s .c om
        Email mail = new SimpleEmail();
        //Configuracion necesaria para GMAIL
        mail.setHostName("mail.pahema.com.ar");
        //mail.setTLS(true);
        mail.setSmtpPort(25);
        //mail.setSSL(true);
        //En esta seccion colocar cuenta de usuario de Gmail y contrasea
        mail.setAuthentication("dante@pahema.com.ar", "Fuerza2015");

        //Cuenta de Email Destino
        // AC? IRIA LA DE ADMINISTRACION DE PAHEMA. mail.addTo("dante.gs@hotmail.com");
        mail.addTo(destino);
        //Cuenta de Email Origen, la misma con la que nos autenticamos
        mail.setFrom("dante@pahema.com.ar", "Pahema - Sistema Tango");
        //Titulo del Email
        mail.setSubject("Aviso de finalizacin de paquete de horas.");
        //Contenido del Email
        mail.setMsg("Estimado cliente,\n" + "Le informamos que su paquete de "
                + (int) paquete.getCantidadHoras() + " horas est por finalizar.\n" + "Le quedan por usar: "
                + (int) paquete.getHorasRestantes() + " horas.\n"
                + "Por favor comunquese con Pahema para el detalle de sus consumos: 4952 - 4789.\n"
                + "Muchas gracias.\n" + "Administracin.");
        mail.send();
    } catch (EmailException e) {
        System.out.println(e.getMessage());
        throw new RuntimeException("Ocurrio un error en el envio del mail");
    }
}

From source file:com.github.triceo.robozonky.notifications.email.AbstractEmailingListener.java

private static Email createNewEmail(final EmailNotificationProperties properties) throws EmailException {
    final Email email = new SimpleEmail();
    email.setCharset(Defaults.CHARSET.displayName());
    email.setHostName(properties.getSmtpHostname());
    email.setSmtpPort(properties.getSmtpPort());
    email.setStartTLSRequired(properties.isStartTlsRequired());
    email.setSSLOnConnect(properties.isSslOnConnectRequired());
    email.setAuthentication(properties.getSmtpUsername(), properties.getSmtpPassword());
    email.setFrom(properties.getSender(), "RoboZonky @ " + properties.getLocalHostAddress());
    email.addTo(properties.getRecipient());
    return email;
}

From source file:de.knurt.fam.core.util.mail.UserMailSender.java

/**
 * send an email without need to put it into the userbox (without saved in
 * database). put only smtp port and host to it as configured in
 * {@link UserMailSender}. do not change anything else but send the email!
 * //from   w w w.j a  v  a  2 s.co m
 * @param raw
 *            all content (subject, msg, attachments, from, to) must be set
 * @return true if sending succeeded.
 */
public static boolean sendWithoutUserBox(Email raw) {
    boolean result = true;
    UserMailSender dse = getInstance();

    raw.setHostName(dse.hostName);
    raw.setSmtpPort(dse.smtpPort);

    if (FamConnector.isDev() == false) {
        try {
            raw.send();
        } catch (EmailException e) {
            result = false;
            FamLog.exception("sendWithoutUserBox: " + e.getMessage(), e, 201106131753l);
        }
    }
    if (result) {
        if (SEND_WITHOUT_METER == Integer.MAX_VALUE) {
            SEND_WITHOUT_METER = 0;
        }
        SEND_WITHOUT_METER++;
    }
    return result;
}

From source file:gobblin.util.EmailUtils.java

/**
 * A general method for sending emails./*w  w  w  . ja v  a  2s  .  c o  m*/
 *
 * @param state a {@link State} object containing configuration properties
 * @param subject email subject
 * @param message email message
 * @throws EmailException if there is anything wrong sending the email
 */
public static void sendEmail(State state, String subject, String message) throws EmailException {
    Email email = new SimpleEmail();
    email.setHostName(state.getProp(ConfigurationKeys.EMAIL_HOST_KEY, ConfigurationKeys.DEFAULT_EMAIL_HOST));
    if (state.contains(ConfigurationKeys.EMAIL_SMTP_PORT_KEY)) {
        email.setSmtpPort(state.getPropAsInt(ConfigurationKeys.EMAIL_SMTP_PORT_KEY));
    }
    email.setFrom(state.getProp(ConfigurationKeys.EMAIL_FROM_KEY));
    if (state.contains(ConfigurationKeys.EMAIL_USER_KEY)
            && state.contains(ConfigurationKeys.EMAIL_PASSWORD_KEY)) {
        email.setAuthentication(state.getProp(ConfigurationKeys.EMAIL_USER_KEY), PasswordManager
                .getInstance(state).readPassword(state.getProp(ConfigurationKeys.EMAIL_PASSWORD_KEY)));
    }
    Iterable<String> tos = Splitter.on(',').trimResults().omitEmptyStrings()
            .split(state.getProp(ConfigurationKeys.EMAIL_TOS_KEY));
    for (String to : tos) {
        email.addTo(to);
    }

    String hostName;
    try {
        hostName = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException uhe) {
        LOGGER.error("Failed to get the host name", uhe);
        hostName = "unknown";
    }

    email.setSubject(subject);
    String fromHostLine = String.format("This email was sent from host: %s%n%n", hostName);
    email.setMsg(fromHostLine + message);
    email.send();
}

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

public static void sendStudentSignUp(String studentFirstName, String studentLastName, Date time) {
    try {//from   ww  w. j  a va  2  s  .  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("You have a new appointment with " + studentFirstName + " " + studentLastName + " on "
                + time + ". Any previously " + "scheduled appointments with them have been canceled.");

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

        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:edu.corgi.uco.sendEmails.java

public static void sendSecretaryNotification(String name) {
    try {//  w ww . jav a  2s  . 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");
        email.setMsg(name + "'s Schedule has been approved. "
                + "Please remove their hold promptly so they may enroll.");

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

        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:edu.corgi.uco.sendEmails.java

public static void sendAdvisorCancel(String emailAddress, String studentFirstName, String studentLastName) {
    try {//from   w w w .  ja v  a 2  s. com
        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 CS Corgi");
        email.setSubject("Advisement Update");
        email.setMsg(
                studentFirstName + " " + studentLastName + "your appointment has been canceled by the advisor."
                        + "You will need to log in to CORGI and sign up for another appointment to get advised."
                        + "Thank you.");
        System.out.print("Email Address: " + emailAddress);
        email.addTo(emailAddress);

        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:edu.corgi.uco.sendEmails.java

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

    try {//from w  ww  .  ja  v  a 2  s  . c  o 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: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 .  java2s  .  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:at.treedb.util.Mail.java

public static void sendMail(String smtpHost, int smtpPort, TransportSecurity transportSecurity, String smtpUser,
        String smtpPassword, String mailTo, String mailFrom, String subject, String message) throws Exception {
    Objects.requireNonNull(mailTo, "Mail.sendMail(): mailTo can not be null!");
    Objects.requireNonNull(subject, "Mail.sendMail(): subject can not be null!");
    Objects.requireNonNull(message, "Mail.sendMail(): message can not be null!");
    Email email = new SimpleEmail();
    email.setHostName(smtpHost);//from   w  ww.  j  a v  a  2s  .co m

    email.setAuthenticator(new DefaultAuthenticator(smtpUser, smtpPassword));
    if (transportSecurity == TransportSecurity.SSL) {
        email.setSSLOnConnect(true);
        email.setSSLCheckServerIdentity(false);
    } else if (transportSecurity == TransportSecurity.STARTTLS) {
        email.setStartTLSRequired(true);
    }
    email.setSmtpPort(smtpPort);
    if (mailFrom != null && !mailFrom.isEmpty()) {
        email.setFrom(smtpUser);
    }
    email.setSubject(subject);
    email.setMsg(message);
    email.addTo(mailTo);
    email.send();
}