Re: Smtp Server error with JavaMail

Discussion in 'Java' started by GaryM, Jul 16, 2003.

  1. GaryM

    GaryM Guest

    Federico <> wrote in
    news::

    > Hi all,
    >
    >
    > I'm trying to utilize the JavaMail package and I've realized a class.
    > This is the constructor's code:



    I am not sure why you are getting the exception. You have got it pretty
    much right; however, I am doubtful of the way you are obtaining the
    transport. Try the following code changes, which use the destination
    address to automatically select the appropriate provider. If it still
    does not work then it points to a classpath issue, however if mail.jar
    is in the path, I don't see how it could be ...


    >
    > public sendMail() throws AddressException, MessagingException {
    >
    > String smtpServer = new String("mail.tin.it");
    > String userId = new String("USERID");
    > String password = new String("PASSWORD");
    >
    > Properties props = new Properties();
    > props.put("mail.smtp.host", smtpServer);
    > props.put("mail.smtp.auth","true");
    > Session session = Session.getDefaultInstance(props, null);
    >

    // InternetAddress to = new InternetAddress("TO_ADDRESS");
    Address to = new InternetAddress("TO_ADDRESS");

    > InternetAddress from = new InternetAddress("FROM_ADDRESS");
    > Message message= new MimeMessage(session);
    > message.setFrom(from);
    > message.setRecipient(Message.RecipientType.TO, to);
    > message.setSubject("Test JavaMail");
    > message.setContent("Ciao Mondo","text/plain");


    // just for completeness you should do this
    message.saveChanges();

    > Transport transport = null;

    // transport = session.getTransport("smtp");
    transport = session.getTransport(to);

    > transport.connect(smtpServer, userId, password);
    > transport.sendMessage(message, message.getAllRecipients());
    > transport.close();
    >}

    <snip>

    Regards,

    Gary
    GaryM, Jul 16, 2003
    #1
    1. Advertising

  2. GaryM

    Federico Guest

    Thank to both Joseph and Gary, but it's still not working.

    The smtp.jar is in the classpath, as the mail.jar and even the
    activation.jar.

    I've tried with the Gary's suggestions in the code, but it's still not
    working.

    What could be!??!?!?!?

    Now is even changed the errore message:

    DEBUG: getProvider() returning
    javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
    Microsystems, Inc]
    java.lang.reflect.InvocationTargetException
    at
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at
    java.lang.reflect.Constructor.newInstance(Constructor.java:274)
    at javax.mail.Session.getService(Session.java:607)
    at javax.mail.Session.getTransport(Session.java:541)
    at javax.mail.Session.getTransport(Session.java:484)
    at javax.mail.Session.getTransport(Session.java:464)
    at sendMail.sendMail.<init>(sendMail.java:43)
    at sendMail.simpleSendMessage.main(simpleSendMessage.java:50)
    Caused by: java.lang.NoSuchMethodError:
    javax.mail.Session.getDebugOut()Ljava/io/PrintStream;
    at
    com.sun.mail.smtp.SMTPTransport.<init>(SMTPTransport.java:72)
    ... 10 more
    javax.mail.NoSuchProviderException: smtp
    at javax.mail.Session.getService(Session.java:611)
    at javax.mail.Session.getTransport(Session.java:541)
    at javax.mail.Session.getTransport(Session.java:484)
    at javax.mail.Session.getTransport(Session.java:464)
    at sendMail.sendMail.<init>(sendMail.java:43)
    at sendMail.simpleSendMessage.main(simpleSendMessage.java:50)
    Exception in thread "main"


    On Wed, 16 Jul 2003 20:42:34 -0000, GaryM <> wrote:

    >Federico <> wrote in
    >news::
    >
    >> Hi all,
    >>
    >>
    >> I'm trying to utilize the JavaMail package and I've realized a class.
    >> This is the constructor's code:

    >
    >
    >I am not sure why you are getting the exception. You have got it pretty
    >much right; however, I am doubtful of the way you are obtaining the
    >transport. Try the following code changes, which use the destination
    >address to automatically select the appropriate provider. If it still
    >does not work then it points to a classpath issue, however if mail.jar
    >is in the path, I don't see how it could be ...
    >
    >
    >>
    >> public sendMail() throws AddressException, MessagingException {
    >>
    >> String smtpServer = new String("mail.tin.it");
    >> String userId = new String("USERID");
    >> String password = new String("PASSWORD");
    >>
    >> Properties props = new Properties();
    >> props.put("mail.smtp.host", smtpServer);
    >> props.put("mail.smtp.auth","true");
    >> Session session = Session.getDefaultInstance(props, null);
    >>

    > // InternetAddress to = new InternetAddress("TO_ADDRESS");
    >Address to = new InternetAddress("TO_ADDRESS");
    >
    >> InternetAddress from = new InternetAddress("FROM_ADDRESS");
    >> Message message= new MimeMessage(session);
    >> message.setFrom(from);
    >> message.setRecipient(Message.RecipientType.TO, to);
    >> message.setSubject("Test JavaMail");
    >> message.setContent("Ciao Mondo","text/plain");

    >
    >// just for completeness you should do this
    >message.saveChanges();
    >
    >> Transport transport = null;

    >// transport = session.getTransport("smtp");
    >transport = session.getTransport(to);
    >
    >> transport.connect(smtpServer, userId, password);
    >> transport.sendMessage(message, message.getAllRecipients());
    >> transport.close();
    >>}

    ><snip>
    >
    >Regards,
    >
    >Gary
    Federico, Jul 17, 2003
    #2
    1. Advertising

  3. GaryM

    GaryM Guest

    Federico <> wrote in
    news::

    > Thank to both Joseph and Gary, but it's still not working.
    >
    > The smtp.jar is in the classpath, as the mail.jar and even the
    > activation.jar.
    >
    > I've tried with the Gary's suggestions in the code, but it's still
    > not working.
    >
    > What could be!??!?!?!?


    Although you get a javax.mail.NoSuchProviderException I think this is a
    red herring as the first line is clearly from the
    javamail.default.providers file in mail.jar. If you have this then you
    have the SMTPTransport class (it is also invoked in the trace too). So
    I no longer think it is a classpath issue.

    I am beginning to suspect the SMTP AUTH. I cannot test this myself
    easily, but I wonder if you can test it with a non-auth server using
    the static method Transport.send(msg)?
    GaryM, Jul 17, 2003
    #3
  4. GaryM

    GaryM Guest

    GaryM <> wrote in
    news:Xns93BAE78B6C1C1R3344324357788499939@216.168.3.44:

    > Although you get a javax.mail.NoSuchProviderException I think this
    > is a red herring as the first line is clearly from the
    > javamail.default.providers file in mail.jar. If you have this then
    > you have the SMTPTransport class (it is also invoked in the trace
    > too). So I no longer think it is a classpath issue.
    >
    > I am beginning to suspect the SMTP AUTH. I cannot test this myself
    > easily, but I wonder if you can test it with a non-auth server
    > using the static method Transport.send(msg)?


    Sorry to followup on my own post. I just did do a test with your code
    on my SMTP AUTH enabled server and it does work.

    You seem to be falling over when the Javamail determines the name of
    the Transport provider from the javamail.default.providers and
    reflection tries to instantiate that class. Therefore:

    1. Can you check that you have the com.* hierarchy in your mail.jar and
    the integrity of the jar is good?

    2. Earlier you referred to "smtp.jar". Can you remove this (it is part
    of mail.jar anyway)?

    3. I'd still like to see if it works on a non AUTH server.


    Here is my debug log:

    DEBUG: JavaMail version 1.3
    DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\j2re1.4.1_
    01\lib\javamail.providers (The system cannot find the file specified)
    DEBUG: !anyLoaded
    DEBUG: not loading resource: /META-INF/javamail.providers
    DEBUG: successfully loaded resource: /META-
    INF/javamail.default.providers
    DEBUG: Tables of loaded providers
    DEBUG: Providers Listed By Class Name:
    {com.sun.mail.smtp.SMTPTransport=javax.mail.Provider
    [TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc],
    com.sun.mail.imap.IMAPStore=javax.mail.Provider
    [STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc],
    com.sun.mail.pop3.POP3Store=javax.mail.Provider
    [STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
    DEBUG: Providers Listed By Protocol: {imap=javax.mail.Provider
    [STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], pop3
    =javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun
    Microsystems, Inc], smtp=javax.mail.Provider
    [TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
    DEBUG: successfully loaded resource: /META-
    INF/javamail.default.address.map
    DEBUG: !anyLoaded
    DEBUG: not loading resource: /META-INF/javamail.address.map
    DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\j2re1.4.1_
    01\lib\javamail.address.map (The system cannot find the file specified)
    DEBUG: getProvider() returning javax.mail.Provider
    [TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG: SMTPTransport trying to connect to host "xxxx", port 25

    <SNIP>
    GaryM, Jul 17, 2003
    #4
  5. GaryM

    Federico Guest

    I've checked everything (apart the integrity of the jar, how can you
    check it?) and it's still not working. Perhaps it's the system.

    Tomorrow I'll try on another system to see what happens

    Anyway thanks for everything.

    Fede


    On Thu, 17 Jul 2003 11:32:29 -0000, GaryM <> wrote:

    >GaryM <> wrote in
    >news:Xns93BAE78B6C1C1R3344324357788499939@216.168.3.44:
    >
    >> Although you get a javax.mail.NoSuchProviderException I think this
    >> is a red herring as the first line is clearly from the
    >> javamail.default.providers file in mail.jar. If you have this then
    >> you have the SMTPTransport class (it is also invoked in the trace
    >> too). So I no longer think it is a classpath issue.
    >>
    >> I am beginning to suspect the SMTP AUTH. I cannot test this myself
    >> easily, but I wonder if you can test it with a non-auth server
    >> using the static method Transport.send(msg)?

    >
    >Sorry to followup on my own post. I just did do a test with your code
    >on my SMTP AUTH enabled server and it does work.
    >
    >You seem to be falling over when the Javamail determines the name of
    >the Transport provider from the javamail.default.providers and
    >reflection tries to instantiate that class. Therefore:
    >
    >1. Can you check that you have the com.* hierarchy in your mail.jar and
    >the integrity of the jar is good?
    >
    >2. Earlier you referred to "smtp.jar". Can you remove this (it is part
    >of mail.jar anyway)?
    >
    >3. I'd still like to see if it works on a non AUTH server.
    >
    >
    Federico, Jul 17, 2003
    #5
  6. GaryM

    Federico Guest

    That's just what I've done.

    I hope to have better news tomorrow.

    Bye
    Fede

    On Thu, 17 Jul 2003 15:50:14 -0000, Gary M <(xx=ry)>
    wrote:

    >Federico <> wrote in
    >news::
    >
    >>
    >> I've checked everything (apart the integrity of the jar, how can you
    >> check it?) and it's still not working. Perhaps it's the system.
    >>
    >> Tomorrow I'll try on another system to see what happens
    >>
    >> Anyway thanks for everything.

    >
    >I use winrar to browse the jar and it also can check the integrity.
    >Please post back when you solve the problem. Sorry I can't help more.
    >
    >Gary
    Federico, Jul 17, 2003
    #6
  7. GaryM

    Roedy Green Guest

    On Thu, 17 Jul 2003 19:20:11 GMT, Federico <> wrote or
    quoted :

    >That's just what I've done.
    >
    >I hope to have better news tomorrow.


    I have written a remailer than uses Java mail. You send it an email
    and it broadcast it to the attached list of people.

    See http://mindprod.com/products.html#BULK

    It comes with commented Java source which may help you in your
    project.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Jul 17, 2003
    #7
  8. GaryM

    Federico Guest

    I've wrote the same code on another machine and it works perfectly

    Really don't know what's happening on the machine where isn't working,
    but I'm happy it works where I have to implement the application :)

    Thank you for all of your suggestion.

    Fede


    On Thu, 17 Jul 2003 15:32:46 GMT, Federico <> wrote:

    >I've checked everything (apart the integrity of the jar, how can you
    >check it?) and it's still not working. Perhaps it's the system.
    >
    >Tomorrow I'll try on another system to see what happens
    >
    >Anyway thanks for everything.
    >
    >Fede
    >
    >
    Federico, Jul 18, 2003
    #8
  9. GaryM

    Scott Yanoff Guest

    Federico wrote:

    > I've wrote the same code on another machine and it works perfectly
    >
    > Really don't know what's happening on the machine where isn't working,
    > but I'm happy it works where I have to implement the application :)


    I do not know the ins and outs of JavaMail, but does the machine where
    this did not work on have access to the mail server you are using? Try
    pinging the mail server hostname from that machine. I believe that
    JavaMail connects to port 25 of the server, so perhaps you could try:

    telnet machineName 25
    EHLO

    You should get some type of greeting message back after typing EHLO.

    Cheers,


    --
    -Scott
    | http://www.yanoff.org | AOL IM: SAY KJY
    Scott Yanoff, Jul 21, 2003
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joseph Millar

    Re: Smtp Server error with JavaMail

    Joseph Millar, Jul 16, 2003, in forum: Java
    Replies:
    0
    Views:
    609
    Joseph Millar
    Jul 16, 2003
  2. Sudsy
    Replies:
    0
    Views:
    424
    Sudsy
    Jul 16, 2003
  3. mrby
    Replies:
    6
    Views:
    868
    GaryM
    May 6, 2004
  4. Rico
    Replies:
    1
    Views:
    8,726
  5. ameyas7
    Replies:
    3
    Views:
    1,800
    javabytes
    Aug 31, 2007
Loading...

Share This Page