Javax.mail.MessagingException: Could not connect to SMTP host: 1

yedez
Messages postés
70
Date d'inscription
dimanche 3 novembre 2013
Statut
Membre
Dernière intervention
28 avril 2015
- 28 avril 2015 à 12:07
Bonjour.

je ne suis pas familiere avec le reseau et ces trucs de smtp e je ne peux pas trouver comment corriger ma faute! est ce que vous pouvez m'aider

SendEmail.java

package com.pfa.Servlets;

import java.util.Properties;

import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

public class SendEmail {
public static void main(String[] args) {

// Recipient's email ID needs to be mentioned.
String to = "hari@gmail.com";

// Sender's email My Office mail server
String from = "hari8750@access.co.in";
String pass = "Password";
String host = "127.0.0.1";
String port = "25";

// Get system properties
Properties properties = System.getProperties();

// Setup mail server
properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.smtp.port", port);
properties.setProperty("mail.smtp.auth", "true");

// Get the default Session object.
Session session = Session.getInstance(properties,
new PasswordAuthenticator(from, pass));
properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.smtp.port", port);
properties.setProperty("mail.smtp.auth", "true");
properties.setProperty("mail.smtp.ssl.enable", "true");
properties.setProperty("mail.smtp.ssl.trust", "*");
properties.setProperty("mail.smtp.sender.address", from);
properties.setProperty("mail.smtp.from", from);

try {
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);

// Set From: header field of the header.
message.setFrom(new InternetAddress(from));

// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO, new InternetAddress(
to));

// Set Subject: header field
message.setSubject("Test Mail");

// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();

// Fill the message
messageBodyPart.setText("Test Mail Success Hari");

// Create a multipar message
Multipart multipart = new MimeMultipart();

// Set text message part
multipart.addBodyPart(messageBodyPart);

// Send the complete message parts
message.setContent(multipart);

// Send message
Transport.send(message);
System.out.println("Sent message successfully....");
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
}