aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes MS Exchange Server... javamail.. Exception.. plz help 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 "MS Exchange Server... javamail.. Exception.. plz help" Watch "MS Exchange Server... javamail.. Exception.. plz help" New topic
Author

MS Exchange Server... javamail.. Exception.. plz help

Ram Sateesh Talari
Greenhorn

Joined: Dec 03, 2003
Posts: 20
Dear Friends

This is the code that I am using.. and stack trace follows the code. Please help..

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class Test
{
public static void main(String args[])
{

try{
Properties p = System.getProperties();

p.put("mail.smtp.host","<prefix>.<exchange server>.com");
p.put("mail.smtp.port","25");

Session s = Session.getDefaultInstance(p);

Message msg = new MimeMessage(s);

msg.setFrom(new InternetAddress("<my email id>"));

msg.setRecipient(Message.RecipientType.TO,new InternetAddress("<my email id>"));

msg.setSubject("hi");

Multipart mp = new MimeMultipart();

BodyPart bp = new MimeBodyPart();
bp.setText("Hello ");

mp.addBodyPart(bp);

msg.setContent(mp);

Transport t = s.getTransport("smtp");
t.send(msg);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

stack trace:
============

javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java
:1407)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1205)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:32
2)
at javax.mail.Service.connect(Service.java:236)
at javax.mail.Service.connect(Service.java:137)
at javax.mail.Service.connect(Service.java:86)
at javax.mail.Transport.send0(Transport.java:150)
at javax.mail.Transport.send(Transport.java:80)
at Test.main(Test.java:34)
Ashish Vegaraju
Ranch Hand

Joined: Aug 19, 2004
Posts: 47
hi Ram,

Your code seems to be right, just check whether you have the following jar files in your classpath.

com.zip
smtp.jar
activation.jar
imap.jar
javax.zip
mail.jar
mailapi.jar
pop3.jar

Cheers

Ashish
[ August 26, 2005: Message edited by: Ashish Vegaraju ]
Ram Sateesh Talari
Greenhorn

Joined: Dec 03, 2003
Posts: 20
thanks a lot Ashish

but there is no problem with the jar files.. this is the actual problem

"host name"

remember that host name should always match with your mail id uptill the domain part of it..

eg. <your id>@<domain>

I had to check out with my administrator(exchange) for the smtp id.. and that's it problem solved.

Cheers
Ram
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
try to telnet ur smtp server at port 25

Rgds,

Seetesh
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


remember that host name should always match with your mail id uptill the domain part of it.

Not necessarily. It just needs to be the name, or IP, of the mail server you are going to use.

Ram Sateesh Talari gives the best bit of advice though:

I had to check out with my administrator

Speak to the administrator of your mail server. Lots of JavaMail problems are nothing more than configuration issues.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ram Sateesh Talari
Greenhorn

Joined: Dec 03, 2003
Posts: 20
Hi Paul

I actually solved it. And there is no problem with the code except for the host name.

Check out your smtp hostname with your Administrator.

Cheers
Ram
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MS Exchange Server... javamail.. Exception.. plz help