17 luglio 2006

Codice Utile - Inviare Una Mail

/* Programma Semplice Per Inviare Una E-Mail. * **************************************************************************** * * ATTENZIONE: Per Funzionare Il Programma Necessita Delle Librerie: * * * 1) javax.mail * * * 2) javax.activation * * * Possono essere scaricate dal sito della Sun Microsystem(http://www.sun.it* * * oppure cercando su internet. * * **************************************************************************** * Autore: Alessio Mario. */
import java.io.*;
import javax.mail.*;
import javax.maio.internet.*;
import javax.activation.*;
import javax.swing.*;
public class Mail {
public static void send(String SmtpHost, int SmtpPort, String From, String To, String subject, String Content) throws AndressException, MessagingException
{ // Create A Mail Session
java.util.Properties props = new java.util.Properties();
props.put("mail.smtp.host",SmtpHost);
props.put("mail.smtp.port",SmtpPort);
Session session = Session.getDefaultInstance(props, null);

// Construct The Message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAndress(From));
msg.setRecipient(Message.RecipientType.TO, new Internet Andress(to));
msg.setSubject(Subject);
msg.setText(Content);

// Send The Message
Transport.send(msg);
}
public static void main(String[]args) throws Exception
{ // Messaggio Di Prova

send("hostname",25,"mario@tiscali.it","siravo@tiscali.it","re:ciao","Come Stai?"); } }