Java project

Sosso
EmailExample.java

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package emailexample; import javax.swing.*; import java.awt.event.*; import java.util.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; /** * * * @author abena */ public class EmailExample extends JFrame implements ActionListener { JButton button = new JButton("Send Email"); public EmailExample() { button.addActionListener(this); this.add(button); } public void actionPerformed(ActionEvent e) { final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; // Get a Properties object Properties props = System.getProperties(); props.setProperty("mail.smtp.host", "smtp.gmail.com"); props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY); props.setProperty("mail.smtp.socketFactory.fallback", "false"); props.setProperty("mail.smtp.port", "465"); props.setProperty("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.auth", "true"); props.put("mail.debug", "true"); props.put("mail.store.protocol", "pop3"); props.put("mail.transport.protocol", "smtp"); final String username = "abena.primo@gmail.com";// final String password = "gt-553acp";// Change try { Session session = Session.getDefaultInstance(props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); // -- Create a new message -- Message msg = new MimeMessage(session); // -- Set the FROM and TO fields -- msg.setFrom(new InternetAddress("abena.primo@gmail.com")); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("acprimo@htu.edu", false)); msg.setSubject("Hello"); msg.setText("How are you"); //this works also: //msg.setContent("<b>How are you</b>","text/html"); msg.setSentDate(new Date()); Transport.send(msg); System.out.println("Message sent."); } catch (MessagingException eX) { System.out.println("Erreur d'envoi, cause: " + eX); } } public static void main(String args[]) { EmailExample frame = new EmailExample(); frame.setVisible(true); frame.setSize(500, 500); frame.pack(); } }