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

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

Introduction

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

Prototype

public Email setSubject(final String aSubject) 

Source Link

Document

Set the email subject.

Usage

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

public String send(String emailAddress, String studentFirstName, String studentLastName) throws EmailException {

    System.out.print("hit send");
    Email email = new SimpleEmail();
    System.out.print("created email file");
    email.setDebug(true);//www .j  a va2 s.co m
    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 Secretary");
    email.setSubject("Advisement Update");
    email.setMsg(studentFirstName + " " + studentLastName
            + " your advisment has been processed and the hold on your account will be removed shortly");
    System.out.print("Email Address: " + emailAddress);
    email.addTo(emailAddress);

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

    email.send();
    System.out.print("sent");

    return null;
}

From source file:json.JsonUI.java

public void enviandoEmail() {
    Properties login = new Properties();
    String properties = "json/login.properties";
    try {/*from   w  w  w .j  a  v a2  s.c o m*/
        InputStream stream = ClassLoader.getSystemClassLoader().getResourceAsStream(properties);
        login.load(stream);
    } catch (IOException ex) {
        System.out.println("Erro: " + ex.getMessage());
    }
    String username = login.getProperty("hotmail.username");
    String password = login.getProperty("hotmail.password");

    try {
        Email email = new SimpleEmail();
        email.setHostName("smtp.live.com");
        email.setSmtpPort(587);
        email.setStartTLSRequired(true);
        email.setAuthenticator(new DefaultAuthenticator(username, password));
        email.setFrom(username);
        email.setSubject(assuntoEmail.getText());
        email.setMsg(jTextAreaMsgEmail.getText());
        email.addTo(emailDestino.getText());
        email.setDebug(true);
        email.send();
        aviso.setText("Mensagem enviada.");
    } catch (EmailException ex) {
        System.out.println("Erro: " + ex.getMessage());
    }

}

From source file:in.flipbrain.controllers.BaseController.java

protected void sendEmail(String to, String subject, String body) throws EmailException {
    logger.debug("Sending email to " + to + "\nSubject: " + subject + "\nMessage: " + body);
    if ("true".equalsIgnoreCase(getConfigValue(Constants.EM_FAKE_SEND)))
        return;/*from   www  .j av  a  2  s.  c  om*/

    Email email = new SimpleEmail();
    email.setHostName(getConfigValue("smtp.host"));
    email.setSmtpPort(Integer.parseUnsignedInt(getConfigValue("smtp.port")));
    email.setAuthenticator(
            new DefaultAuthenticator(getConfigValue("smtp.user"), getConfigValue("smtp.password")));
    email.setSSLOnConnect(Boolean.parseBoolean(getConfigValue("smtp.ssl")));
    email.setFrom(getConfigValue("smtp.sender"));
    email.setSubject(subject);
    email.setMsg(body);
    email.addTo(to);
    email.send();
}

From source file:edu.br.tcc.ManagedBean.TrabalhosBean.java

public Formulario enviarEmail(Formulario trabalho) {
    System.out.println("entrou no metodo do mb enviarEmail");
    try {/*from   www  .  j  a v  a  2  s . c  om*/
        System.out.println("teste: " + trabalho.getEmail());

        Email emailSimples = new SimpleEmail();

        emailSimples.setHostName("smtp.live.com");
        emailSimples.setStartTLSEnabled(true);
        emailSimples.setSmtpPort(587);
        emailSimples.setDebug(true);
        emailSimples.setAuthenticator(new DefaultAuthenticator("Seu email outlook", "sua senha"));
        emailSimples.setFrom("Seu email outlook");
        emailSimples.setSubject(formulario.getAssunto());
        emailSimples.setMsg(formulario.getTexto() + "     " + caminho2 + trabalho.getMatricula() + ".docx");
        emailSimples.addTo(trabalho.getEmail());
        emailSimples.send();
    } catch (EmailException ex) {
        //   System.out.println(""+ex);
        Logger.getLogger(FormularioDAO.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;

}

From source file:com.waveerp.sendMail.java

public void sendMsg(String strSource, String strSourceDesc, String strSubject, String strMsg,
        String strDestination, String strDestDesc) throws Exception {

    // Call the registry management system                    
    registrySystem rs = new registrySystem();
    // Call the encryption management system
    desEncryption de = new desEncryption();
    de.Encrypter("", "");

    String strHost = rs.readRegistry("NA", "NA", "NA", "EMAILHOST");
    String strPort = rs.readRegistry("NA", "NA", "NA", "EMAILPORT");
    String strUser = rs.readRegistry("NA", "NA", "NA", "EMAILUSER");
    String strPass = rs.readRegistry("NA", "NA", "NA", "EMAILPASSWORD");

    log(DEBUG, strHost + "|" + strPort + "|" + strUser + "|" + strPass);

    //Decrypt the encrypted password.
    strPass = de.decrypt(strPass);/*  w w  w .  j a v a  2 s  .com*/

    Email email = new SimpleEmail();
    email.setHostName(strHost);
    email.setSmtpPort(Integer.parseInt(strPort));
    email.setAuthenticator(new DefaultAuthenticator(strUser, strPass));
    email.setTLS(false);
    email.setFrom(strSource, strSourceDesc);
    email.setSubject(strSubject);
    email.setMsg(strMsg);

    email.addTo(strDestination, strDestDesc);
    email.send();

}

From source file:de.eod.jliki.users.jsfbeans.UserRegisterBean.java

/**
 * Adds a new user to the jLiki database.<br/>
 *///  w  w  w  . ja  v a  2 s  .  c o m
public final void addNewUser() {
    final User newUser = new User(this.username, this.password, this.email, this.firstname, this.lastname);
    final String userHash = UserDBHelper.addUserToDB(newUser);

    if (userHash == null) {
        Messages.addFacesMessage(null, FacesMessage.SEVERITY_ERROR, "message.user.register.failed",
                this.username);
        return;
    }

    UserRegisterBean.LOGGER.debug("Adding user: " + newUser.toString());

    final FacesContext fc = FacesContext.getCurrentInstance();
    final HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();
    final ResourceBundle mails = ResourceBundle.getBundle("de.eod.jliki.EMailMessages",
            fc.getViewRoot().getLocale());
    final String activateEMailTemplate = mails.getString("user.registration.email");
    final StringBuffer url = request.getRequestURL();
    final String serverUrl = url.substring(0, url.lastIndexOf("/"));

    UserRegisterBean.LOGGER.debug("Generated key for user: \"" + userHash + "\"");

    final String emsLink = serverUrl + "/activate.xhtml?user=" + newUser.getName() + "&key=" + userHash;
    final String emsLikiName = ConfigManager.getInstance().getConfig().getPageConfig().getPageName();
    final String emsEMailText = MessageFormat.format(activateEMailTemplate, emsLikiName, this.firstname,
            this.lastname, this.username, emsLink);

    final String emsHost = ConfigManager.getInstance().getConfig().getEmailConfig().getHostname();
    final int emsPort = ConfigManager.getInstance().getConfig().getEmailConfig().getPort();
    final String emsUser = ConfigManager.getInstance().getConfig().getEmailConfig().getUsername();
    final String emsPass = ConfigManager.getInstance().getConfig().getEmailConfig().getPassword();
    final boolean emsTSL = ConfigManager.getInstance().getConfig().getEmailConfig().isUseTLS();
    final String emsSender = ConfigManager.getInstance().getConfig().getEmailConfig().getSenderAddress();

    final Email activateEmail = new SimpleEmail();
    activateEmail.setHostName(emsHost);
    activateEmail.setSmtpPort(emsPort);
    activateEmail.setAuthentication(emsUser, emsPass);
    activateEmail.setTLS(emsTSL);
    try {
        activateEmail.setFrom(emsSender);
        activateEmail.setSubject("Activate jLiki Account");
        activateEmail.setMsg(emsEMailText);
        activateEmail.addTo(this.email);
        activateEmail.send();
    } catch (final EmailException e) {
        UserRegisterBean.LOGGER.error("Sending activation eMail failed!", e);
        return;
    }

    this.username = "";
    this.password = "";
    this.confirm = "";
    this.email = "";
    this.firstname = "";
    this.lastname = "";
    this.captcha = "";
    this.termsOfUse = false;
    this.success = true;

    Messages.addFacesMessage(null, FacesMessage.SEVERITY_INFO, "message.user.registered", this.username);
}

From source file:at.treedb.util.Mail.java

/**
 * //from w w  w .  j a v a 2 s .c o m
 * @param sendTo
 * @param subject
 * @param message
 * @throws EmailException
 */
public void sendMail(String mailTo, String mailFrom, String subject, String message) throws Exception {
    Objects.requireNonNull(mailTo, "Mail.sendMail(): mailTo can not be null!");
    Objects.requireNonNull(mailFrom, "Mail.sendMail(): mailFrom 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);

    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);
    email.setFrom(mailFrom);
    email.setSubject(subject);
    email.setMsg(message);
    email.addTo(mailTo);
    email.send();
}

From source file:com.northernwall.hadrian.workItem.email.EmailWorkItemSender.java

private void emailWorkItem(String subject, String body) {
    try {/*from  ww  w  . jav a 2 s. c o  m*/
        if (emailTos.isEmpty()) {
            return;
        }
        Email email = new SimpleEmail();
        if (smtpHostname != null) {
            email.setHostName(smtpHostname);
        }
        email.setSmtpPort(smtpPort);
        if (smtpUsername != null && smtpPassword != null) {
            email.setAuthenticator(new DefaultAuthenticator(smtpUsername, smtpPassword));
        }
        email.setSSLOnConnect(smtpSsl);
        email.setFrom(emailFrom);
        email.setSubject(subject);
        email.setMsg(body);
        for (String emailTo : emailTos) {
            email.addTo(emailTo);
        }
        email.send();

        if (emailTos.size() == 1) {
            logger.info("Emailing work item to {} with subject {}", emailTos.get(0), subject);
        } else {
            logger.info("Emailing work item to {} and {} other email addresses with subject {}",
                    emailTos.get(0), (emailTos.size() - 1), subject);
        }
    } catch (EmailException ex) {
        throw new RuntimeException("Failure emailing work item, {}", ex);
    }
}

From source file:net.scran24.user.server.services.HelpServiceImpl.java

private void sendEmailNotification(String name, String surveyId, String number, List<String> addresses) {
    Email email = new SimpleEmail();

    email.setHostName(smtpHostName);/*www  .j  ava  2 s  .c o  m*/
    email.setSmtpPort(smtpPort);
    email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword));
    email.setSSLOnConnect(true);
    email.setCharset(EmailConstants.UTF_8);

    try {
        email.setFrom(fromEmail, fromName);
        email.setSubject("Someone needs help completing their survey");
        email.setMsg("Please call " + name + " on " + number + " (survey id: " + surveyId + ")");

        for (String address : addresses)
            email.addTo(address);

        email.send();
    } catch (EmailException e) {
        log.error("Failed to send e-mail notification", e);
    }
}

From source file:com.pkrete.locationservice.endpoint.mailer.impl.EmailServiceImpl.java

/**
 * Sends the given EmailMessage to the recipients defined in the message.
 * Returns true if and only if the message was successfully sent to all the
 * recipients; otherwise false./* w  w  w. j  a va2s.  c o m*/
 *
 * @param message email message to be sent
 * @return true if and only if the message was successfully sent to all the
 * recipients; otherwise false
 */
@Override
public boolean send(EmailMessage message) {
    if (message == null) {
        logger.warn("Message cannot be null.");
        return false;
    }
    logger.debug("Create new \"{}\" email message.", message.getType().toString());

    if (message.getRecipients().isEmpty()) {
        logger.info("No recipients defined. Nothing to do -> exit.");
        return false;
    }
    Email email = new SimpleEmail();
    email.setHostName(PropertiesUtil.getProperty("mail.host"));
    email.setSmtpPort(this.converterService.strToInt(PropertiesUtil.getProperty("mail.port")));
    email.setAuthenticator(new DefaultAuthenticator(PropertiesUtil.getProperty("mail.user"),
            PropertiesUtil.getProperty("mail.password")));
    email.setTLS(true);
    try {
        // Set from address
        email.setFrom(message.getFrom());
        // Set subject
        email.setSubject(message.getSubject());

        // Build message body
        StringBuilder body = new StringBuilder();
        if (!message.getHeader().isEmpty()) {
            body.append(message.getHeader()).append("\n\n");
        }
        if (!message.getMessage().isEmpty()) {
            body.append(message.getMessage()).append("\n\n");
        }
        if (!message.getFooter().isEmpty()) {
            body.append(message.getFooter()).append("\n\n");
        }
        if (!message.getSignature().isEmpty()) {
            body.append(message.getSignature()).append("\n\n");
        }

        // Set message contents
        email.setMsg(body.toString());

        // Add message receivers
        for (String recipient : message.getRecipients()) {
            logger.info("Add recipient \"{}\".", recipient);
            email.addTo(recipient);
        }

        // Send message
        email.send();

        logger.info("Email was succesfully sent to {} recipients.", message.getRecipients().size());
    } catch (Exception e) {
        logger.error("Failed to send \"{}\" email message.", message.getType().toString());
        logger.error(e.getMessage());
        return false;
    }
    return true;
}