Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try to telnet ur smtp server at port 25

Rgds,

Seetesh
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic