I have asked this question earlier in jboss section and also on jboss website. But I was wrong in posting my query. The solution that I got was jBoss specific. But my requirement needs me to send the mail without using the jBoss mail service. So I'm posting this again. I want to send the mail using simple java mail API. I can't use jBoss services. This is the code that I'm using
Now the problem is that when the tr.connect method is called, I get a messaging connection. I am connecting to localhost as you can see. I was told to use JES for sending the mail. I also found that the username and password is not needed while connecting when using JES. But I'm not able to make this work. I changed the code to use the mail server of my company. I used the url of the mail server and the username and password of the mail server. But still I'm getting Messaging Exception. There is nothing wrong with the code as it is working on the live site on which it is actually deployed. So basically I just need to configure JES or any other mail server properly. Can anyone give me an idea or a web resource to make this work.
Also can I use a server like gmail to send the mail using my username and password of gmail. I know this may sound stupid if I'm wrong ...
Ok I'm one step closer to the solution. My antivirus was blocking port 25 to prevent worms from doing mass mails. Actually someone told me to try to connect to 127.0.0.1 25 through telnet to check if the port is blocked. So I tried telnet and couldn't connect. So then I checked my antivirus and found the problem there. But now I'm facing another problem. I am using JES to send the mails. But my JES is giving this error while sending emails
Well thanks Jelle for the information. I think there was a problem because of configuration of JES. In the mail.conf file there was an entry of allowed outgoing from addresses which was not configured. This is the part of the mail.conf file
So I added my mail address to the allowed list. Not there is no error code with the error but still the error is there. This is the new error from JES now
Now there are a few things to clarify. I have changed the email id but the actual email ID that I'm using is valid. But the from and to fields have the same email id if that makes a difference. Also I'm having some internet connection problem today so it might be due to that. I can send mails and chat using normal gmail but JES might not be able to handle the network problem. But I'm not sure what is the cause of this problem...
Well I couldn't configure JES on my local machine so I used the email server of my company. Still the code was not working. I was getting this exception
Sending message failed: javax.mail.MessagingException: 554 Sending address not accepted due to spam filter
I was not able to find out the reason for the error. The same sending address was working on a test program that I created and which I ran from the command line. So I had to change the mail.jar in the jboss 4.0.4. I replaced the file with the new mail.jar that I downloaded from internet. And boom, it started working. I wrote this just for anyone who faces a similar problem. I know that there can't be a problem with jBoss but I think it could be because of the version of JDK on my system or because of a similar problem...