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:beanView.MbVListaEmail.java

public void sendMail() {
    String subject = nombre + " " + eMail;
    try {//from   w  w  w  . j  a  va 2  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 = "";

    }

}

From source file:com.mycollab.servlet.EmailValidationServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String smtpUserName = request.getParameter("smtpUserName");
    String smtpPassword = request.getParameter("smtpPassword");
    String smtpHost = request.getParameter("smtpHost");
    String smtpPort = request.getParameter("smtpPort");
    String tls = request.getParameter("tls");
    String ssl = request.getParameter("ssl");

    int mailServerPort = 25;
    try {/* www .  java 2s .  c o m*/
        mailServerPort = Integer.parseInt(smtpPort);
    } catch (Exception e) {
        LOG.info("The smtp port value is not a number. We will use default port value is 25");
    }
    try {
        Email email = new SimpleEmail();
        email.setHostName(smtpHost);
        email.setSmtpPort(mailServerPort);
        email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword));
        if ("true".equals(tls)) {
            email.setStartTLSEnabled(true);
        } else {
            email.setStartTLSEnabled(false);
        }

        if ("true".equals(ssl)) {
            email.setSSLOnConnect(true);
        } else {
            email.setSSLOnConnect(false);
        }
        email.setFrom(smtpUserName);
        email.setSubject("MyCollab Test Email");
        email.setMsg("This is a test mail ... :-)");
        email.addTo(smtpUserName);
        email.send();
    } catch (EmailException e) {
        PrintWriter out = response.getWriter();
        out.write("Cannot establish SMTP connection. Please recheck your config.");
        LOG.warn("Can not login to SMTP", e);
    }
}

From source file:com.ning.billing.util.email.DefaultEmailSender.java

private void sendEmail(final List<String> to, final List<String> cc, final String subject, final Email email)
        throws EmailApiException {
    try {//from w  ww .ja v  a 2s.  com
        email.setSmtpPort(config.getSmtpPort());
        if (config.useSmtpAuth()) {
            email.setAuthentication(config.getSmtpUserName(), config.getSmtpPassword());
        }
        email.setHostName(config.getSmtpServerName());
        email.setFrom(config.getDefaultFrom());

        email.setSubject(subject);

        if (to != null) {
            for (final String recipient : to) {
                email.addTo(recipient);
            }
        }

        if (cc != null) {
            for (final String recipient : cc) {
                email.addCc(recipient);
            }
        }

        email.setSSL(config.useSSL());

        log.info("Sending email to {}, cc {}, subject {}", new Object[] { to, cc, subject });
        email.send();
    } catch (EmailException ee) {
        throw new EmailApiException(ee, ErrorCode.EMAIL_SENDING_FAILED);
    }
}

From source file:com.projetIF4.controller.MailControleur.java

public void mail() throws EmailException {
    Email email = new SimpleEmail();
    email.setCharset("UTF-8");
    email.setHostName("smtp.googlemail.com");
    email.setSmtpPort(465);
    email.setAuthenticator(new DefaultAuthenticator("fst.rnu.info@gmail.com", "adminFST123456789"));
    email.setSSLOnConnect(true);//from w w w . j  av a  2s  .c om
    email.setFrom("fst.rnu.info@gmail.com", "Dpartement Informatique FST");
    email.setSubject(objet);
    email.setMsg(message);
    email.addTo(mailDestination);
    email.send();
}

From source file:com.packtpub.e4.advanced.event.mailman.MailSender.java

@Override
public void handleEvent(Event event) {
    String topic = event.getTopic();
    if (topic.startsWith("smtp/")) {
        String importance = topic.substring("smtp/".length());
        String to = (String) event.getProperty("To");
        String from = (String) event.getProperty("From");
        String subject = (String) event.getProperty("Subject");
        String body = (String) event.getProperty("DATA");
        try {//from   w  w w.  j a va 2s .com
            Email email = new SimpleEmail();
            email.setDebug(false);
            email.setHostName(hostname);
            email.setSmtpPort(port);
            email.setFrom(from);
            email.addTo(to);
            email.setSubject(subject);
            email.setMsg(body);
            email.addHeader("Importance", importance);
            email.send();
            log(LogService.LOG_INFO, "Message sent successfully to " + to);
        } catch (EmailException e) {
            log(LogService.LOG_ERROR, "Error occurred" + e);
        }
    }
}

From source file:com.github.frapontillo.pulse.email.EmailNotifier.java

/**
 * Send an email, using the provided parameters, notifying if the pipeline succeeded or errored.
 *
 * @param parameters The {@link EmailNotifierConfig} to use.
 * @param isSuccess  {@code true} to report a success, {@code false} to report an error.
 *//*w w w.j a  v a2 s  . co  m*/
private void sendEmail(EmailNotifierConfig parameters, boolean isSuccess) {
    if (parameters.getAddresses() == null || parameters.getAddresses().length == 0) {
        return;
    }
    try {
        Email email = new SimpleEmail();
        email.setHostName(parameters.getHost());
        email.setSmtpPort(parameters.getPort());
        email.setAuthenticator(new DefaultAuthenticator(parameters.getUsername(), parameters.getPassword()));
        email.setSSLOnConnect(parameters.getUseSsl());
        email.setFrom(parameters.getFrom());
        email.setSubject(parameters.getSubject());
        String body;
        if (isSuccess) {
            body = parameters.getBodySuccess();
        } else {
            body = parameters.getBodyError();
        }
        body = body.replace("{{NAME}}", getProcessInfo().getName());
        email.setMsg(body);
        email.addTo(parameters.getAddresses());
        email.send();
    } catch (EmailException e) {
        logger.error(e);
        e.printStackTrace();
    }
}

From source file:FacultyAdvisement.ImagineBean.java

public String submitRequest() {

    String emailCourses = "";

    for (Course c : currentCourses) {
        emailCourses += "<li>" + c.getSubject() + " " + c.getNumber() + "</li>";
    }/*from   w  ww.j  av a  2  s.  c om*/

    try {
        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("Microsoft Imagine Account");
        email.setMsg("<font size=\"3\" style=\"font-family:verdana\"> \n" + "<ul><li>Student Name: "
                + student.getFirstName() + " " + student.getLastName() + "</li><li>Student Major: "
                + student.getMajorCode() + "<li>Current Courses: <ol>" + emailCourses + "</ol></li></ul> "
                + "Student Email if needed for response: " + student.getUsername()
                + "\n<p align=\"center\">UCO Faculty Advisement</p></font>");
        email.addTo("uco.faculty.advisement@gmail.com");
        email.send();
    } catch (EmailException ex) {
        Logger.getLogger(VerificationBean.class.getName()).log(Level.SEVERE, null, ex);
    }

    return "/customerFolder/imagineConfirm";
}

From source file:ch.fihlon.moodini.business.token.control.TokenService.java

@SneakyThrows
private void sendChallenge(@NotNull final String email, @NotNull final Challenge challenge) {
    final SmtpConfiguration smtp = configuration.getSmtp();
    final Email mail = new SimpleEmail();
    mail.setHostName(smtp.getHostname());
    mail.setSmtpPort(smtp.getPort());
    mail.setAuthenticator(new DefaultAuthenticator(smtp.getUser(), smtp.getPassword()));
    mail.setSSLOnConnect(smtp.getSsl());
    mail.setFrom(smtp.getFrom());/*from   w  w  w.j  a va2s .  c om*/
    mail.setSubject("Your challenge to login to Moodini");
    mail.setMsg(String.format("Your one time challenge, valid for 10 minutes: %s", challenge.getChallenge()));
    mail.addTo(email);
    mail.send();
}

From source file:com.basetechnology.s0.agentserver.mail.AgentMail.java

public int sendMessage(User user, String toEmail, String toName, String subject, String message,
        String messageTrailer1, String messageTrailer2) throws AgentServerException {
    try {/*from ww  w .j  a  va2s  .  c o m*/
        // Wait until we have mail access
        agentServer.mailAccessManager.wait(user, toEmail);

        int messageId = ++nextMessageId;
        log.info("Sending mail on behalf of user " + user.id + " with message Id " + messageId + " To: '<"
                + toName + ">" + toEmail + "' Subject: '" + subject + "'");

        Email email = new SimpleEmail();
        email.setDebug(debug);
        email.setHostName(mailServerHostName);
        email.setSmtpPort(mailServerPort);
        email.setAuthenticator(new DefaultAuthenticator(mailServerUserName, mailServerUserPassword));
        email.setTLS(true);
        email.setFrom(mailServerFromEmail, mailServerFromName);
        // TODO: Reconsider whether we want to always mess with subject line
        email.setSubject(subject + " (#" + messageId + ")");
        email.setMsg(message + messageTrailer1 + (messageTrailer2 != null ? messageId + messageTrailer2 : ""));
        email.addTo(toEmail, toName);
        email.send();
        log.info("Message sent");

        // Return the message Id
        return messageId;
    } catch (EmailException e) {
        e.printStackTrace();
        throw new AgentServerException("EmailException sending email - " + e.getMessage());
    }
}

From source file:com.mirth.connect.server.util.SMTPConnection.java

public void send(String toList, String ccList, String from, String subject, String body) throws EmailException {
    Email email = new SimpleEmail();
    email.setHostName(host);// www . j a  v  a2s . c  o  m
    email.setSmtpPort(Integer.parseInt(port));
    email.setSocketConnectionTimeout(socketTimeout);
    email.setDebug(true);

    if (useAuthentication) {
        email.setAuthentication(username, password);
    }

    if (StringUtils.equalsIgnoreCase(secure, "TLS")) {
        email.setTLS(true);
    } else if (StringUtils.equalsIgnoreCase(secure, "SSL")) {
        email.setSSL(true);
    }

    for (String to : StringUtils.split(toList, ",")) {
        email.addTo(to);
    }

    if (StringUtils.isNotEmpty(ccList)) {
        for (String cc : StringUtils.split(ccList, ",")) {
            email.addCc(cc);
        }
    }

    email.setFrom(from);
    email.setSubject(subject);
    email.setMsg(body);
    email.send();
}