my dog learned polymorphism
The moose likes Other JSE/JEE APIs and the fly likes excveption in mail api please help 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 "excveption in mail api please help" Watch "excveption in mail api please help" New topic

excveption in mail api please help

jawwad ahmed
Ranch Hand

Joined: Dec 01, 2001
Posts: 179
Well i have many tried to send email .But the exception arise can any body tell where i am wrong.
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class MailExample {
public static void main (String args[]) throws Exception {

// Get system properties
Properties props = System.getProperties();
// Setup mail server
// Get session
Session session = Session.getDefaultInstance(props, null);
// Define message
MimeMessage message = new MimeMessage(session);
// Set the from address
message.setFrom(new InternetAddress
// Set the to address
new InternetAddress(""));
// Set the subject
message.setSubject("Hello JavaMail");
// Set the content
message.setText("Welcome to JavaMail i got it");
// Send message
Exception in thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: mail.yaho, port: 25;
nested exception is: Operation timed out: no further informa
at javax.mail.Transport.send0(
at javax.mail.Transport.send(
at MailExample.main(
Jawwad Ahmed
Ankur Goyal

Joined: Feb 04, 2002
Posts: 13
firstly, it is not "" but "".
secondly, even if u correct the server name, it won't work because yahoo has now restricted access to it's pop/smtp servers and one can't connect(for free) to it through mail clients.(Try accessing ur yahoo account thru outlook, it wud fail.)
Rest of the code is fine. Just change the server. Try out with's free

Let me know if I am wrong ! <img src="smile.gif" border="0">
Mirza Galib

Joined: Jun 02, 2002
Posts: 12 is the address of server on which http service is running . u need mail server address of yahoo server . try 2 make a class file that query a DNS server for MX record . Through this u can make a generic application which can send mail anywhere .

"Hain aur bhee duniya mein sukhanwar bahut acche.<br />Kehte hein ke Galib ka hai andaz-e-bayaan aur."
I agree. Here's the link:
subject: excveption in mail api please help
It's not a secret anymore!