File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes urgent help in java  mail 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 "urgent help in java  mail" Watch "urgent help in java  mail" New topic
Author

urgent help in java mail

bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40


when i compiled and run it.i am geeting following errors in command prompt


E:\>javac SendMailUsingAuthentication.java

E:\>java SendMailUsingAuthentication
Exception in thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: localhost
, port: 465;
nested exception is:
java.net.ConnectException: Connection refused: no further information
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java
:68)
at SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:25)


thanks in advance...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Please http://faq.javaranch.com/java/UseCodeTags. I've added them for you this time. Also, http://faq.javaranch.com/java/EaseUp.

You are trying to connect to a mail server on port 465 on your own computer. Are you sure that a) there is a mail server running on that computer, and b) if it is, is it using port 465 instead of the regular port 25?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
no mail server running in that computer..what may be problem?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

You are trying to connect to a mail server on your own computer (localhost, see the error message), but there is nothing running there. Of course it can't connect.

If I comment out props.put("mail.smtp.host", SMTP_HOST_NAME); and change debug to true (and provide my own username / password), it is trying to connect but it then hangs. That's why I changed debug to true - to see what's going on.

If I then change the port to 25 (the default, and that is definitely open on smtp.gmail.com), it connects just perfectly.

So the properties I've used:
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
thanks rob for your quick reply.as you said i have changed default port number 25.still i am getting following error

E:\>java SendMailUsingAuthentication
Exception in thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command f
irst. j15sm3857046waf.51

at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java
:68)
at SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:25)

i have made, props.put("mail.smtp.starttls.enable","true"); still i am getting error.wht may be the problem?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

That's odd, that worked for me.

What happens if you remove both props.put("mail.smtp.starttls.enable","true"); lines"
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
1st i changed to default port no 25,same error.then i comment two lines ,

then i am geting same error..wht can i do rob?do you have any sample java mail program?

E:\>java SendMailUsingAuthentication
Exception in thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command f
irst. j15sm3910082waf.51

at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java
:68)
at SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:25)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Sorry, I don't know anymore. But it does seem that you need to put that line back.
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40


if i compiled and runned it.i am getting following error...

E:\>java SendMailUsingAuthentication
Exception in thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command f
irst. j39sm3965339waf.10

at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java
:68)
at SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:25)

or any one have sample javamail coding fully??.i did it urgently..thanks in advance
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Like I said, I don't know anymore.

I just copied your exact code, changed the SMTP_AUTH_USER and SMTP_AUTH_PWD to my own account settings, changed the address in emailList to one of my other email addresses, and ran the code. The console printed "Sucessfully Sent mail to All Users", and I got the test mail in my mailbox, although it did use the authenticated user, not "xyz@gmail.com" to send from.
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
rob i crossed half way..i changed following setting

after i complied and ran that code.The console printed as "Sucessfully Sent mail to All Users" but i did not got my testmail in specfied emailList id.moreover i used authenticated user emails id in both emailFromAddress and emailList..

when i checked,i found my test mail in Queue folder(C:\Inetpub\mailroot\Queue)..what may be problem?....waiting for your replies...thanks in advance...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

First of all, don't post anything that even looks like a real password anywhere on the Internet. It's a potential security risk. I changed it for you.

It uses the local SMTP server from IIS for some reason. Try switching off your SMTP service (Control Panel -> Administrative Tools -> Services, select Simple Mail Transport Protocol (SMTP), stop it), and see if the emails are then still sent out.
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
as you said early,i had stopped smtp service.i get following error again

D:\>java SendMailUsingAuthentication
Exception in thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: localhost
, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java
:68)
at SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:25)

if i started again smtp service,i am getting console as"Sucessfully Sent mail to All Users",and same text mail in queue folder,my test mail is not deliverying ...


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

You're still sending through your local machine. That shouldn't happen if you have enabled props.put("mail.smtp.host", SMTP_HOST_NAME);
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
ok..if i sent through local machine also..i am not getting my test mail to my inbox?rob any sugesstion
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
right now i am working in windows 2000 machine with smtp service..do i need any domain with stmp service?i should buy domain to send java mail?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

I don't think this is a Java problem any longer, but a mail server configuration problem. Like I said, your code works for me when I connect directly to smtp.gmail.com on port 25. Apparently you are not able to use that mail server, because you keep ending up on the local mail server. That one is not configured properly to be able to send messages, it seems.

The IIS SMTP server receives your messages just fine, as it pops up in the C:\Inetpub\mailroot\Queue folder. If it then cannot send them from there, IIS has a problem, not your Java code. Perhaps you should check out some of the Microsoft forums to find out why IIS will not work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: urgent help in java mail