aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Sending Mail using Java 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 "Sending Mail using Java" Watch "Sending Mail using Java" New topic
Author

Sending Mail using Java

Jayavardhan Ncbr
Greenhorn

Joined: Jul 25, 2011
Posts: 9
Hi,

I am new to Java.

I want to know how to send Mail message using Java.

Can any one tell me the steps.


I used Java Mail sample source code , but i am getting error at transport.send().

Thanks in advance
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10520
    
    9

What error did you get? Can you post the stack trace?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jayavardhan Ncbr
Greenhorn

Joined: Jul 25, 2011
Posts: 9
Maneesh Godbole wrote:What error did you get? Can you post the stack trace?



Hi,

This is the error i got.


--Exception handling in msgsendsample.java
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: Could not connect to SMTP host: 10.40.9.50, port: 25, response: 421



at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at Emailmsg.main(Emailmsg.java:43)
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10520
    
    9

Is there an SMTP server running at that IP and port? Do you have a firewall running (which is probably blocking the port access)
Jayavardhan Ncbr
Greenhorn

Joined: Jul 25, 2011
Posts: 9
Maneesh Godbole wrote:Is there an SMTP server running at that IP and port? Do you have a firewall running (which is probably blocking the port access)


Hi,

No. firewall is off.

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10520
    
    9

Maneesh Godbole wrote:Is there an SMTP server running at that IP and port?
Angus Comber
Ranch Hand

Joined: Jul 16, 2011
Posts: 90
To check your SMTP server you can use telnet commands to test how to send your email.

eg telnet hostname 25

HELO <domainname>

Maybe the smtp server requires special authentication.
Nam Ha
Ranch Hand

Joined: Aug 05, 2011
Posts: 50

Notice the response code:

class javax.mail.MessagingException: Could not connect to SMTP host: 10.40.9.50, port: 25, response: 421


According to SMTP spec:

421: Service not available, closing transmission channel


That means there is a server at the specified IP but it does not have SMTP service.


Java Object Creation
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
    
    4
If this help:

1. I used Apache common mail.

2. For one open wifi A, I can send the mail perfectly.

3. With the same code, I have the same issue with anothe open wifi B (see below error). So somewhere, there is a blockage in the wifi B. I am interest to know what/where exactly is.


 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Sending Mail using Java