JCoder87
09-11-2008, 10:38
Ciao a tutti... spero che qualcuno conosca la Java Mail, perchè è da un paio di ore che mi stò inalberando:
allora:
Ho del codice che deve inviare un e-mail, ma una volta lanciato mi va in eccezione perchè la porta 25 è chiusa e non si riesce a connettere col server SMTP da me specificato...
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class MailExample {
public static void main (String args[]) throws Exception {
String host = "smtp.email.msn.com";
String from = "xxx@xx.it";
String to = "mio_indirizzo@hotmail.it";
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
// Get session
Session session = Session.getDefaultInstance(props, null);
// Define message
MimeMessage message = new MimeMessage(session);
// Set the from address
message.setFrom(new InternetAddress(from));
// Set the to address
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
// Set the subject
message.setSubject("Hello JavaMail");
// Set the content
message.setText("Welcome to JavaMail");
// Send message
Transport.send(message);
}
}
Il problema è che già in passato avevo usato questo tipo di codice e mai nessun problema... E'capitato a qualcun altro??
Grazie...
allora:
Ho del codice che deve inviare un e-mail, ma una volta lanciato mi va in eccezione perchè la porta 25 è chiusa e non si riesce a connettere col server SMTP da me specificato...
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class MailExample {
public static void main (String args[]) throws Exception {
String host = "smtp.email.msn.com";
String from = "xxx@xx.it";
String to = "mio_indirizzo@hotmail.it";
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
// Get session
Session session = Session.getDefaultInstance(props, null);
// Define message
MimeMessage message = new MimeMessage(session);
// Set the from address
message.setFrom(new InternetAddress(from));
// Set the to address
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
// Set the subject
message.setSubject("Hello JavaMail");
// Set the content
message.setText("Welcome to JavaMail");
// Send message
Transport.send(message);
}
}
Il problema è che già in passato avevo usato questo tipo di codice e mai nessun problema... E'capitato a qualcun altro??
Grazie...