Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

MS Exchange Server - SMTP - Exception : Connection reset

843830Aug 31 2005 — edited Sep 2 2005
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)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 30 2005
Added on Aug 31 2005
1 comment
496 views