• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error while running a simple java mail application

 
Ratheesh Narayanan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Can anyone help me in this??

While I am running a simple java mail send application I am getting an error saying..

----------------------Error message------------------------------
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: 172.16.65.1, port: 80
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at SimpleSender.send(SimpleSender.java:41)
at SimpleSender.main(SimpleSender.java:61)
----------------------End of message------------------------------

I have changed the port from default 25 to 80 since my proxy server port number is 80.

The complete source is given below..

//---------------Source for SimpleSender.java--------------------
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class SimpleSender
{

public static void send(String smtpServer, String to, String from, String subject, String body)
{
try
{
Properties props = System.getProperties();

props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.port", "80");
Session session = Session.getDefaultInstance(props, null)

Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse
(to,false));

Transport.send(msg);

System.out.println("Message sent OK.");
}
catch (Exception ex)
{
ex.printStackTrace();
}
}

public static void main(String args[])
{
String smtpServer="172.16.65.1";
String to="ratheesh.nan@gmail.com";
String from="ratheesh@stgbangalore.com";
String subject="hi";
String body="This is just a trail HI...";

send(smtpServer, to, from, subject, body);
}
}
//---------------------End or SimpleSender.java----------------------
 
fred Joly
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javax.mail.MessagingException: Could not connect to SMTP host: 172.16.65.1, port: 80



172.16.65.1 is a private IP adress, your own adress on your lan.
You need the adress of a SMTP Server. Your internet provider should give you this adress or URL. If you don't know, ask your lan administrator.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your proxy runs on port 80, then it's probably an HTTP proxy, not an SMTP proxy, and of no use to you. Have you tried a direct connection? Make sure you use the correct IP address, as was suggested above.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic