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:AccessControl.java

/**
 * Send email message for external notifications
 *
 * @param subject Email Subject Text//ww w.  ja  v a  2  s .  c om
 * @param message Email Message Text
 */
private static void sendEmail(String subject, String message) {

    try {
        if (EMAIL_ENABLED && EMAIL_FROM != null && !EMAIL_FROM.isEmpty()) {
            Email email = new SimpleEmail();
            email.setHostName(EMAIL_SERVER);
            email.setSmtpPort(EMAIL_PORT);
            email.setFrom(EMAIL_FROM);
            email.addTo(EMAIL_TO);
            email.setSubject(subject);
            email.setMsg(message);
            email.send();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.clavain.alerts.Methods.java

private static void sendMail(String title, String message, String emailaddy) {
    try {/* w w w.j a va  2 s.  com*/
        Email email = new SimpleEmail();
        email.setHostName(p.getProperty("mailserver.host"));
        email.setSmtpPort(Integer.parseInt(p.getProperty("mailserver.port")));
        if (p.getProperty("mailserver.useauth").equals("true")) {
            email.setAuthentication(p.getProperty("mailserver.user"), p.getProperty("mailserver.pass"));
        }
        if (p.getProperty("mailserver.usessl").equals("true")) {
            email.setSSLOnConnect(true);
        } else {
            email.setSSLOnConnect(false);
        }
        email.setFrom(p.getProperty("mailserver.from"));
        email.setSubject("[MuninMX] " + title);
        email.setMsg(message);
        email.addTo(emailaddy);
        email.send();
    } catch (Exception ex) {
        logger.warn("Unable to send Mail: " + ex.getLocalizedMessage());
    }
}

From source file:net.sasasin.sreader.batch.publish.GMailPublisher.java

@Override
public void publish(ContentViewId content) {
    try {//  ww w  .jav  a 2s.c  o m
        Email email = new SimpleEmail();
        email.setHostName("smtp.gmail.com");
        email.setSmtpPort(587);
        email.setStartTLSEnabled(true);
        email.setCharset("UTF-8");

        email.setAuthenticator(new DefaultAuthenticator(content.getEmail(), content.getPassword()));

        email.setFrom(content.getEmail());
        email.addTo(content.getEmail());
        email.setSubject(content.getTitle());
        email.setMsg(content.getUrl() + "\n" + content.getFullText());

        email.send();
        log(content);
    } catch (EmailException e) {
        e.printStackTrace();
    }
}

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);// 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:ch.sbb.releasetrain.utils.emails.SMTPUtilImpl.java

@Override
public void send(String absender, String empfaenger, String betreff, String text) {
    try {/*from w  w w .  ja  v a 2s . co  m*/
        final Email email = new SimpleEmail();
        email.setHostName(mailhost);
        email.setSmtpPort(mailport);
        email.setFrom(absender);
        email.setSubject(betreff);
        email.setMsg(text);
        email.addTo(empfaenger);
        email.send();
        log.info("mail sent to: " + empfaenger);
    } catch (final EmailException e) {
        log.error(e.getMessage(), e);
    }
}

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

public void sendEmail(final EmailData emailData) {
    try {/*  w ww  . ja  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
 * /*from ww  w  . ja  v  a2  s .  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
 * /*from   w  w w  . ja v  a 2s  .  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//from  ww w .jav a 2s  .co  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:com.esofthead.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");

    int mailServerPort;
    try {/*from ww w. ja  v a  2s  . c o  m*/
        mailServerPort = Integer.parseInt(smtpPort);
    } catch (Exception e) {
        PrintWriter out = response.getWriter();
        out.write("Port must be an integer value");
        return;
    }
    try {
        Email email = new SimpleEmail();
        email.setHostName(smtpHost);
        email.setSmtpPort(mailServerPort);
        email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword));
        if (tls.equals("true")) {
            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.");
        return;
    }
}