File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ram Sateesh Talari
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to telnet ur smtp server at port 25

Rgds,

Seetesh
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ram Sateesh Talari
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic