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

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

Introduction

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

Prototype

public void setHostName(final String aHostName) 

Source Link

Document

Set the hostname of the outgoing mail server.

Usage

From source file:at.tugraz.kmi.medokyservice.ErrorLogNotifier.java

public static void errorEmail(String msg) {

    Email email = new SimpleEmail();
    email.setHostName("something.com");
    email.setSmtpPort(465);/* ww  w .  ja va2  s . c o  m*/
    DefaultAuthenticator auth = new DefaultAuthenticator("username", "pwd");
    email.setAuthenticator(auth);
    email.setSSLOnConnect(true);
    try {
        email.setFrom("email address");
        email.setSubject("[MEDoKyService] Error");
        email.setMsg(msg);
        email.addTo("yourmail.com");
        email.send();
    } catch (EmailException e) {
        e.printStackTrace();
    }

}

From source file:br.fgv.util.EmailSender.java

public static void enviarEmail(String body, String subject) throws EmailException {

    StringBuffer sb = new StringBuffer("");
    sb.append(body);/*ww  w  .j av a  2 s .  c om*/

    Email email = new SimpleEmail();
    email.setHostName("smtp.gmail.com");

    email.setDebug(true);
    email.setSSLOnConnect(true);

    email.addTo("wesley.seidel@gmail.com");

    email.setAuthentication("wseidel.fgv", "batavinhofgv");

    email.setFrom("wseidel.fgv@gmail.com");
    email.setSubject(subject);
    email.setMsg(sb.toString());

    email.send();
}

From source file:com.aprodher.actions.util.EmailUtils.java

public static Email conectaEmail() throws EmailException {
    Email email = new SimpleEmail();
    email.setHostName(HOSTNAME);
    email.setSmtpPort(587);/* w w  w  .  j ava  2s .c  o  m*/
    email.setAuthenticator(new DefaultAuthenticator(USERNAME, PASSWORD));
    email.setSSL(true);
    email.setTLS(true);
    email.setFrom(EMAILORIGEM);
    return email;
}

From source file:io.jhonesdeveloper.swing.util.EmailUtil.java

public static void sendBasicText(String hostName, String username, String password, String from, String subject,
        String msg, String[] to) throws EmailException {
    Email email = new SimpleEmail();
    email.setHostName(hostName);
    email.setSmtpPort(465);//from ww  w. ja  va  2  s  .co m
    email.setAuthenticator(new DefaultAuthenticator(username, password));
    email.setSSLOnConnect(true);
    email.setFrom(from);
    email.setSubject(subject);
    email.setMsg(msg);
    email.addTo(to);
    email.send();
}

From source file:de.alpharogroup.message.system.service.CommonsEmailSendService.java

public static void sendEmail(final EmailConfiguration config, InfoMessageModel model) throws EmailException {
    // TODO make class for email config...
    Email email = new SimpleEmail();
    email.setHostName(config.getHostName());
    email.setSmtpPort(config.getSmtpPort());
    email.setFrom(model.getApplicationSenderAddress());
    email.setSubject(model.getMessageContentModel().getSubject());
    email.setMsg(model.getMessageContentModel().getContent());
    email.addTo(model.getRecipientEmailContact());
    email.send();/*from w  w  w .j  a v a  2s .com*/
}

From source file:connection.EmailSending.java

public static void sendTextEmail(String subject, String content, String recipientEmail) {
    Email email = new SimpleEmail();

    email.setHostName(MailInfor.HOST_NAME);
    email.setSmtpPort(465);/* w  w  w  .  j  a va 2  s .  c o  m*/
    email.setAuthenticator(new DefaultAuthenticator(MailInfor.EMAIL_SENDER, MailInfor.PASSWORD));
    email.setSSLOnConnect(true);

    try {
        email.setFrom(MailInfor.EMAIL_SENDER);
        email.setSubject(subject);
        email.setMsg(content);
        email.addTo(recipientEmail);

        email.send();
    } catch (EmailException ex) {
        Logger.getLogger(EmailSending.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:model.EmailJava.java

public static void enviarEmail(String userEmail) {
    try {/*  w  w  w.  j av a  2  s. co  m*/
        Email email = new SimpleEmail();
        email.setHostName("smtp.googlemail.com");
        email.setSmtpPort(465);
        //email.setAuthenticator(new DefaultAuthenticator("username", "password"));
        email.setAuthentication("codbarzmgbr@gmail.com ", "streetworkout2014");
        email.setSSLOnConnect(true);

        email.setFrom("jpmuniz88@gmail.com");

        email.setSubject("CodbarZ");
        email.setMsg("Junte-se ao CodbarZ. \n" + "Atleta junte-se ao nosso time, \n"
                + "empreendedores junte-se para nos apoiar, \n"
                + "Associe essa ideia, um projeto de inovado e aberto a todos que desejar evoluir com CodbarZ");
        email.addTo(userEmail);
        email.send();

    } catch (EmailException ex) {
        Logger.getLogger(EmailJava.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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

/**
 * /*from  www.  ja  v a2  s . c o 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:controller.SendMailMachine.java

public static void sendMail(Cart cart, String recipientEmail) {
    Email email = new SimpleEmail();

    email.setHostName(HOST_NAME);
    email.setSmtpPort(465);//from  ww w  .  j  av  a 2  s . com
    email.setAuthenticator(new DefaultAuthenticator(EMAIL_SENDER, PASSWORD));
    email.setSSLOnConnect(true);

    String subject = "Thng tin ha n";
    String content = "\t\t\tTRUNG TM MUA SM BITTORRENT\n\nChi tit n hng ca bn: \n";
    for (Map.Entry<Integer, Item> entrySet : cart.getCartItem().entrySet()) {
        Item item = entrySet.getValue();
        content += item.getWatch().getName() + "\t\t\t\t\t\t" + item.getQuantity() + " x "
                + ((int) item.getWatch().getPrice()) + "000 VND\n";
    }
    content += "Tng ha n: " + ((int) cart.sumPrice()) + "000 VND";
    try {
        email.setFrom(EMAIL_SENDER);
        email.setCharset("UTF-8");
        email.setSubject(subject);
        email.setMsg(content);

        email.addTo(recipientEmail);

        email.send();
    } catch (EmailException ex) {

        ex.printStackTrace();
    }
}

From source file:com.esofthead.mycollab.servlet.InstallUtils.java

public static void checkSMTPConfig(String host, int port, String username, String password, boolean auth,
        boolean isStartTls, boolean isSSL) {
    try {/*from   w  w w .  j a  va 2  s  . co  m*/
        Properties props = new Properties();
        if (auth) {
            props.setProperty("mail.smtp.auth", "true");
        } else {
            props.setProperty("mail.smtp.auth", "false");
        }
        if (isStartTls) {
            props.setProperty("mail.smtp.starttls.enable", "true");
            props.setProperty("mail.smtp.startssl.enable", "true");
        } else if (isSSL) {
            props.setProperty("mail.smtp.startssl.enable", "false");
            props.setProperty("mail.smtp.ssl.enable", "true");
            props.setProperty("mail.smtp.ssl.socketFactory.fallback", "false");

        }

        Email email = new SimpleEmail();
        email.setHostName(host);
        email.setSmtpPort(port);
        email.setAuthenticator(new DefaultAuthenticator(username, password));
        if (isStartTls) {
            email.setStartTLSEnabled(true);
        } else {
            email.setStartTLSEnabled(false);
        }

        if (isSSL) {
            email.setSSLOnConnect(true);
        } else {
            email.setSSLOnConnect(false);
        }
        email.setFrom(username);
        email.setSubject("MyCollab Test Email");
        email.setMsg("This is a test mail ... :-)");
        email.addTo(username);
        email.send();
    } catch (Exception e) {
        throw new UserInvalidInputException(e);
    }
}