I'm a beginner in socket programming. So I can't solve my project's errors, I can't even understand where the problem is!
here is my code:
public static void main(String[] args) {
String to = "parisa.roodheleh@gmail.com";
String from = "parisainfinity@yahoo.com";
String host = "localhost";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host",host);
Session session = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("This is the subject Line!");
message.setText("This is autual message!");
Transport.send(message);
System.out.println("sent message successfully...");
}catch(MessagingException mex){
mex.printStackTrace();
}
}
and here is some errors:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2054)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
any idea?