• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

excveption in mail api please help

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
props.put("mail.smtp.host","mail.yahoo.com");
// Get session
Session session = Session.getDefaultInstance(props, null);
// Define message
MimeMessage message = new MimeMessage(session);
// Set the from address
message.setFrom(new InternetAddress
"[email protected]"));
// Set the to address
message.addRecipient(Message.RecipientType.TO,
new InternetAddress("[email protected]"));
// Set the subject
message.setSubject("Hello JavaMail");
// Set the content
message.setText("Welcome to JavaMail i got it");
// Send message
Transport.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
o.com, port: 25;
nested exception is:
java.net.NoRouteToHostException: Operation timed out: no further informa
tion
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at MailExample.main(MailExample.java:35)
Thanks
Jawwad Ahmed
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
firstly, it is not "mail.yahoo.com" but "smtp.mail.yahoo.com".
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 www.themail.com....it's free
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mail.yahoo.com 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 .
 
Everybody's invited. Except this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic