com.dominion.salud.pedicom.negocio.tools.MAILTest.java Source code

Java tutorial

Introduction

Here is the source code for com.dominion.salud.pedicom.negocio.tools.MAILTest.java

Source

/*
 * Copyright (C) 2017 Dominion Global
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.dominion.salud.pedicom.negocio.tools;

import java.io.File;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.MultiPartEmail;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author jcgonzalez
 */
public class MAILTest {

    private static final Logger logger = LoggerFactory.getLogger(MAILTest.class);

    private static final String POP = "";
    private static final String SMTP = "mail.juntadeandalucia.es";
    private static final int PUERTO = 465;
    private static final String USUARIO = "ugcfarmacia.hvm.sspa@juntadeandalucia.es";
    private static final String PASSWORD = "Farmacia2121";
    private static final String FROM = "ugcfarmacia.hvm.sspa@juntadeandalucia.es";
    private static final String TO = "juancarlos.gonzalez@dominion-global.com";

    @Ignore
    @Test
    public void send() {
        try {
            MultiPartEmail email = new MultiPartEmail();
            email.setHostName(SMTP);
            email.setAuthenticator(new DefaultAuthenticator(USUARIO, PASSWORD));
            email.setDebug(true);
            email.setSmtpPort(PUERTO);
            email.setStartTLSEnabled(true);

            email.setSSLOnConnect(true);

            email.setFrom(FROM, FROM);
            email.addTo(TO, TO);
            email.setSubject("Correo de Prueba");
            email.attach(new File("/home/jcgonzalez/TMP/a.hl7"));

            email.send();
        } catch (Exception e) {
            logger.error(e.toString());
        }
    }
}