
{filelink=1009}
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class EmailJava
{
// Envoyer un email à un contact
public static void envoyer_email(String serveurSTMP, int portSTMP, String from, String to, String sujet,
String message) throws Exception
{
String username = "nom d'utilisateur";
String password = "mot de passe";
java.util.Properties props = new java.util.Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(props, null);
Transport transport = session.getTransport("smtp");
transport.connect(serveurSTMP, portSTMP, username, password);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(sujet);
msg.setText(message);
Transport.send(msg);
}
public static void main(String[] args) throws Exception {
envoyer_email("smtp.gmail.com", 465, "de@gm.com", "ae@rmail.com", "invitation", "mon message");
}
}