wood burning stoves*
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
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

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:, 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)
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


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

public static void main(String args[])
String smtpServer="";
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:, port: 80 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

Joined: Mar 22, 2005
Posts: 41101
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
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?