Package webalbum.functions

Source Code of webalbum.functions.GoogleMail

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package webalbum.functions;
import webalbum.config.GMAILConfig;
import java.net.*;
import java.util.*;
import java.io.*;
import javax.mail.Transport;
import javax.mail.Message;
import javax.mail.* ;
import javax.mail.internet.*;
import javax.activation.*;

/**
*
* @author Jampy
*/



public class GoogleMail {

    public boolean SendMail(String to, String subject, String messageText) throws NoSuchProviderException, MessagingException  {

        String from = "h1n1gallery@gmail.com";


        boolean sessionDebug = true;
        Properties props = System.getProperties();
        props.put("mail.host", GMAILConfig.HOST);
        props.put("mail.transport.protocol.", "smtp");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.", "true");
        props.put("mail.smtp.port", "465");
        props.put("mail.smtp.socketFactory.fallback", "false");
        props.put("mail.smtp.socketFactory.class", GMAILConfig.SSL_FACTORY);
        Session mailSession = Session.getDefaultInstance(props, null);
        mailSession.setDebug(sessionDebug);
        Message msg = new MimeMessage(mailSession);
        try {
        msg.setFrom(new InternetAddress(from));
        InternetAddress[] address = {new InternetAddress(to)};
        msg.setRecipients(Message.RecipientType.TO, address);
        msg.setSubject(subject);
        msg.setContent(messageText, "text/html");
              } catch(Exception e) {
           return false;
        }
        Transport transport = mailSession.getTransport("smtp");
        boolean jo = true;
        transport.connect(GMAILConfig.HOST, GMAILConfig.USER, GMAILConfig.PASS);

        try {
            transport.sendMessage(msg, msg.getAllRecipients());
            transport.close();
            return true;
        }
        catch (Exception err) {
            transport.close();
            return false;
        }





            }
}
TOP

Related Classes of webalbum.functions.GoogleMail

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.