Here is my java code to send email, whenever i run the code it shows javax.mail.MessagingException: Could not connect to SMTP host: ipaddress, port: 25; I even tried changing the port number, still same error.. can anyone help me.. (i have included mail.jar and activation.jar to project)
public static void main(String arfs[]) throws UnknownHostException
{
InetAddress address = InetAddress.getLocalHost();
String to="gggg@gmail.com";
String from="vvvvv@gmail.com";
String host=address.getHostAddress();
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host",host);
properties.setProperty("mail.smtp.port", "25");
Session session = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("vvvv@gmail.com"));
message.addRecipient(Message.RecipientType.TO,new InternetAddress("ggggg@gmail.com"));
message.setSubject("test email");
message.setText("hello");
Transport.send(message);
System.out.println("message sent successfully....");
}
catch(MessagingException mex)
{
mex.printStackTrace();
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire