• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error while running a simple java mail application

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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----------------------
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic