• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

problem /exceptions in sending a mail using JavaMail

 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all
I am developing an application of sending a mail using JavaMail api. My program is below:

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class sms
{
public static void main(String args[])
{
try
{
String strstrsmtserver="smtp.bol.net.in";
String strto="pradeepsingh999@yahoo.co.in";
String strfrom="sandeepsumal@bol.net.in";
String strsubject="Hello";
String bodytext="This is my first java mail program";


sms s=new sms();





s.send(strstrsmtserver,strto,strfrom,strsubject,bodytext);


}

catch(Exception e)
{
System.out.println("usage:java sms"+"strstrsmtpserver tosddress fromaddress subjecttext bodyText");
}
System.exit(0);

}





public void send(String strsmtpserver,String strto,String strfrom ,String strsubject,String bodytext)
{
try
{
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties p=new Properties(System.getProperties());












if(strsmtpserver!=null)
{
p.put("mail.transport.protocol","smtp");
p.put("mail.smtp.host","pradeepsingh999@yahoo.co.in");

p.put("mail.smtp.port","25");

}


Session session=Session.getDefaultInstance(p);

Message msg=new MimeMessage(session);




Transport trans = session.getTransport("smtp");
trans.connect("smtp.bol.net.in","sandeepsumal@bol.net.in","1234563757");





msg.setFrom(new InternetAddress(strfrom));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(strto,false));



msg.setSubject(strsubject);
msg.setText(bodytext);


msg.setHeader("X-Mailer","mtnlmail");
msg.setSentDate(new Date());

Transport.send(msg);

System.out.println("Message sent OK.");
}

catch(Exception ex)
{
System.out.println("here is error");
ex.printStackTrace();
}


}


}




It compiles fine but showing exceptions at run time.Please help me to remove these exceptions.I am new to this JavaMail and it is my first program of javamail.Please also tell me how to use smtp server.I am using MTNL 's internet connection having smtp.bol.net.in server.

exceptions are:

Here is exception

Javax.mail.MessagingException:Could not connect to SMTP host : smtp.bol.net.in, port :25;
Nested exception is :
Java.net.ConnectException:Connection refused: connect
At com.sun.mail.smtp.SMTPTransport.openServer<SMTPTransport.java:1227>
At com.sun.mail.smtp.SMTPTransport.protocolConnect<SMTPTransport.java:322>
At javax.mail.Service .connect(Service.java:236>
At javax.mail.Service.connect<Service.java:137>
At sms.send<sms.java:77>
At sms.main<sms.java:24>
;



[ September 01, 2008: Message edited by: pradeep singh ]
[ September 01, 2008: Message edited by: pradeep singh ]
 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try pinging your SMTP server to see if network connectivity is in place.
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Please could you tell me how to check it?
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to assume you haven't heard of or used the ping utility before. Modern OS's tend to come with a ping utility, so go to the command line of the operating system you are using and type:

ping smtp.bol.net.in

And see what the result is.
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I pinged ing smtp.bol.net.in and the result is:-

Pinging smtp.bol.net.in [203.94.243.193] with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's your problem then. You need to speak to your Network Administrator and/or the owner of the SMTP server to figure out why you can't reach that machine, it's probably a firewall issue or the SMTP server is shutdown or you have an incorrect IP mapping for that machine name.
 
Ajay Saxena
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope you got the root cause of the issue now.
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't rely fully on PING if you are using WinDoze as PING can be disabled.
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

There's your problem then. You need to speak to your Network Administrator and/or the owner of the SMTP server to figure out why you can't reach that machine, it's probably a firewall issue or the SMTP server is shutdown or you have an incorrect IP mapping for that machine name.




Network Administrator ?Who?This is my home pc.?Could i correct it myself & how?
Can i use some other free smtp server ?If yes then please tell me about them and How?

Thankx
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't ping or tracert it either so it's probably down or has moved. I can only recommend trying Google for free smtp servers, I'm not aware of any myself
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The days of publicly accessible mail servers are long gone. You can run one on your own machine, though. Apache James is easy to get started with.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic