This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes Error while running a simple java mail application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Error while running a simple java mail application" Watch "Error while running a simple java mail application" New topic
Author

Error while running a simple java mail application

Ratheesh Narayanan
Ranch Hand

Joined: Oct 30, 2004
Posts: 38
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----------------------


SCJP 1.4 & SCBCD 1.5
fred Joly
Ranch Hand

Joined: Jan 19, 2006
Posts: 55
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
Marshal

Joined: Mar 22, 2005
Posts: 41095
    
  44
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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error while running a simple java mail application
 
Similar Threads
smtps and javamail
JavaMail will not let me to authenticate myself
Error while sending a mail using javaMail - reg.
at the time automail generation
how to mail send in servlets or jsp?