help please, my brain stop thinking!!! what is wrong with this simple mail client code
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   greg_zhang
Posted On:   Saturday, August 2, 2003 08:35 PM

I got the following error, have no clue what is wrong. the MX for yahoo.com is mx1.mail.yahoo.com. here is the error message javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: Could not connect to SMTP host: mx1.mail.yahoo.com, port: 25; nested exception is: java.net.NoRouteToHostException: Operation timed out: no further information i double checked that the MX server mx1.mail.yahoo.com is one among many valid MX server returned after i use some DNS lookup utility classes, and i even try to use    More>>

I got the following error, have no clue what is wrong.
the MX for yahoo.com is mx1.mail.yahoo.com.


here is the error message


javax.mail.SendFailedException: Sending failed;

nested exception is:


javax.mail.MessagingException: Could not

connect to SMTP host: mx1.mail.yahoo.com, port: 25;

nested exception is:

java.net.NoRouteToHostException: Operation timed

out: no further information





i double checked that the MX server

mx1.mail.yahoo.com

is one among many valid MX server returned

after i use some DNS lookup utility classes,

and i even try to use socket to connec that

server and read a byte,seems work, which means

it is alive. but just fail again and again when

i try to use javamail to send a simple text

message to my yahoo account,

weiweil@yahoo.com,

any help is really appretiated.





here is the code





import java.util.*;

import javax.mail.*;

import javax.mail.internet.*;


public class TT

{

private static final String smtpServer

= "mx1.mail.yahoo.com";



static void sendMail(String to, String from, String

subject, String text) throws MessagingException

{

Properties props = new Properties();


props.put("mail.smtp.host", smtpServer);


props.put("mail.debug", "false");


Session mailSession = Session.getDefaultInstance(props, null);


mailSession.setDebug(false);


MimeMessage msg = new MimeMessage(mailSession);


msg.setFrom(new InternetAddress(from));


msg.setRecipients(Message.RecipientType.TO,

new InternetAddress[] {

new InternetAddress(to)

} );


msg.setSubject(subject);


msg.setSentDate(new Date());


msg.setHeader("X-Mailer", "Example Mailer");


msg.setText(text);


msg.saveChanges();


Transport.send(msg);

}



public static void main(String args[])

{

try{

sendMail("weiweilee@yahoo.com",

"weiweilee@yahoo.com" ,

"String subject",

" String text");

}

catch(Exception e) {

System.out.println(e);

}

}



}

   <<Less

Re: help please, my brain stop thinking!!! what is wrong with this simple mail client code

Posted By:   Anonymous  
Posted On:   Tuesday, August 12, 2003 04:32 AM

Hi,

Your code is apparently correct, I have tried it and i have found the following results.

  1. First try was unsuccessful (same error as you)

  2. Second try I receive an exception related to supported encodings

  3. After that I tried again the program (with no changes), and it works (at least as far as I know)


Conclusion, your code is correct, and it could be a problem (temporary or not) using yahoo as a mail exchanger, could you use another mail exchanger?. If you are just testing your code, there are SMTP servers based on Java as James.


Bye,

David

Re: help please, my brain stop thinking!!! what is wrong with this simple mail client code

Posted By:   Nic_Daniau  
Posted On:   Tuesday, August 12, 2003 03:56 AM

I don't think you need

msg.saveChanges();

when using the Transport.send static method. This only applies when using the Transport.sendMessage non-static method.

Re: help please, my brain stop thinking!!! what is wrong with this simple mail client code

Posted By:   Andrew_Modelski  
Posted On:   Tuesday, August 5, 2003 02:55 AM

I can't spot any problems with your code, but you might want to try running the example program given here http://developer.java.sun.com/developer/onlineTraining/JavaMail/exercises/MailSending/solution/MailExample.java


If it allows you to send, you can start comparing it to your program.


If it doesn't work, then I tend to thing the problem has to do with the yahoo mail server.
About | Sitemap | Contact