Thread: java mail issue

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Atlanta
    Posts
    9
    Rep Power
    0

    java mail issue


    Hey all,
    I'm attempting to set up an automated monitoring program that will test connections to some db's, ping various servers to see if alive and other connection testing. The successful results will be written to a log and the unsuccessful attempts will generate an email to a help desk. I have a connections, ping-ing and logging set up, but I'm having some trouble with the mail. I have downloaded the javamail and javabean requirements and installed them. I have replace the real email address below with fictious, but in my program the email address are real. Can anyone provide some guidance?

    Here is my classpath: .;C:\JBuilder9\jdk1.4\lib\tools.jar;%CATALINA_HOME%\common\lib\servlet.jar;c:\javamail-1.3.1\mail.jar;c:\jaf-1.0.1\activation.jar;c:\javamail-1.3.1\lib\imap.jar;c:\javamail-1.3.1\lib\mailapi.jar:c:\javamail-1.3.1\lib\pop3.jar;c:\javamail-1.3.1\lib\smtp.jar

    I also have copied each jar file into every conceviable directory. IN addition, I have configured the libararies in JBuilder. Here is my code:

    // method to send an email
    public void monitorEmail ()
    {
    // SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
    String to = "someone@nowhere.com";
    String from = "me@nowhere.com";
    // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
    String host = "mail.nowhere.com";

    // Create properties, get Session
    Properties props = new Properties();

    // If using static Transport.send(),
    // need to specify which host to send it to
    props.put("mail.nowhere.com", host);
    // To see what is going on behind the scene
    props.put("mail.debug", "true");
    Session session = Session.getInstance(props);

    try {
    // Instantiatee a message
    Message msg = new MimeMessage(session);

    //Set message attributes
    msg.setFrom(new InternetAddress(from));
    InternetAddress[] address = {new InternetAddress(to)};
    msg.setRecipients(Message.RecipientType.TO, address);
    msg.setSubject("Test E-Mail through Java");
    msg.setSentDate(new Date());

    // Set message content
    msg.setText("This is a test message for the monitor program" +
    "to test for a oracle connection. Testing a failed" +
    "connection. This is only a test!");

    //Send the message
    Transport.send(msg);
    }
    catch (MessagingException mex) {
    // Prints all nested (chained) exceptions as well
    mex.printStackTrace();
    }
    }

    And Finally, here is the debug trace:

    DEBUG: JavaMail version 1.3.1

    DEBUG: java.io.FileNotFoundException: C:\JBuilder9\jdk1.4\jre\lib\javamail.providers (The system cannot find the file specified)

    DEBUG: URL jar:file:/C:/JBuilder9/jdk1.4/jre/lib/ext/imap.jar!/META-INF/javamail.providers

    DEBUG: successfully loaded resource: jar:file:/C:/JBuilder9/jdk1.4/jre/lib/ext/imap.jar!/META-INF/javamail.providers

    DEBUG: URL jar:file:/C:/JBuilder9/jdk1.4/jre/lib/ext/pop3.jar!/META-INF/javamail.providers

    DEBUG: successfully loaded resource: jar:file:/C:/JBuilder9/jdk1.4/jre/lib/ext/pop3.jar!/META-INF/javamail.providers

    DEBUG: URL jar:file:/C:/JBuilder9/jdk1.4/jre/lib/ext/smtp.jar!/META-INF/javamail.providers

    DEBUG: successfully loaded resource: jar:file:/C:/JBuilder9/jdk1.4/jre/lib/ext/smtp.jar!/META-INF/javamail.providers

    DEBUG: URL jar:file:/C:/javamail-1.3.1/lib/imap.jar!/META-INF/javamail.providers

    DEBUG: successfully loaded resource: jar:file:/C:/javamail-1.3.1/lib/imap.jar!/META-INF/javamail.providers

    DEBUG: URL jar:file:/C:/javamail-1.3.1/lib/pop3.jar!/META-INF/javamail.providers

    DEBUG: successfully loaded resource: jar:file:/C:/javamail-1.3.1/lib/pop3.jar!/META-INF/javamail.providers

    DEBUG: URL jar:file:/C:/javamail-1.3.1/lib/smtp.jar!/META-INF/javamail.providers

    DEBUG: successfully loaded resource: jar:file:/C:/javamail-1.3.1/lib/smtp.jar!/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 Microsy stems, 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: URL jar:file:/C:/JBuilder9/jdk1.4/jre/lib/ext/smtp.jar!/META-INF/javamail.address.map

    DEBUG: successfully loaded resource: jar:file:/C:/JBuilder9/jdk1.4/jre/lib/ext/smtp.jar!/META-INF/javamail.address.map

    DEBUG: URL jar:file:/C:/javamail-1.3.1/lib/smtp.jar!/META-INF/javamail.address.map

    DEBUG: successfully loaded resource: jar:file:/C:/javamail-1.3.1/lib/smtp.jar!/META-INF/javamail.address.map

    DEBUG: java.io.FileNotFoundException: C:\JBuilder9\jdk1.4\jre\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 false

    DEBUG SMTP: trying to connect to host "localhost", port 25


    220 tboyce Microsoft ESMTP MAIL Service, Version: 5.0.2195.6713 ready at Mon, 19 Apr 2004 21:28:17 -0400

    DEBUG SMTP: connected to host "localhost", port: 25


    EHLO tboyce

    250-tboyce Hello [127.0.0.1]

    250-AUTH GSSAPI NTLM LOGIN

    250-AUTH=LOGIN

    250-SIZE 2097152

    250-PIPELINING

    250-DSN

    250-ENHANCEDSTATUSCODES

    250-8bitmime

    250-BINARYMIME

    250-CHUNKING

    250-VRFY

    250 OK

    DEBUG SMTP: Found extension "AUTH", arg "GSSAPI NTLM LOGIN"

    DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""

    DEBUG SMTP: Found extension "SIZE", arg "2097152"

    DEBUG SMTP: Found extension "PIPELINING", arg ""

    DEBUG SMTP: Found extension "DSN", arg ""

    DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""

    DEBUG SMTP: Found extension "8bitmime", arg ""

    DEBUG SMTP: Found extension "BINARYMIME", arg ""

    DEBUG SMTP: Found extension "CHUNKING", arg ""

    DEBUG SMTP: Found extension "VRFY", arg ""

    DEBUG SMTP: Found extension "OK", arg ""

    DEBUG SMTP: use8bit false

    MAIL FROM:<me@nowhere.com>

    250 2.1.0 me@nowhere.com....Sender OK

    RCPT TO:<someone@nowhere.com>

    550 5.7.1 Unable to relay for someone@nowhere.com

    DEBUG SMTP: Invalid Addresses

    DEBUG SMTP: someone@nowhere.com

    DEBUG SMTP: Sending failed because of invalid destination addresses

    RSET

    javax.mail.SendFailedException: Sending failed;
    nested exception is:
    class javax.mail.SendFailedException: Invalid Addresses;
    nested exception is:
    class javax.mail.SendFailedException: 550 5.7.1 Unable to relay for someone@nowhere.com


    at javax.mail.Transport.send0(Transport.java:218)

    at javax.mail.Transport.send(Transport.java:80)

    at Monitor.connTask.monitorEmail(connTask.java:94)250 2.0.0 Resetting

    QUIT

    at Monitor.connTask.run(connTask.java:41)

    at java.util.TimerThread.mainLoop(Timer.java:432)

    at java.util.TimerThread.run(Timer.java:382)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2003
    Posts
    1,152
    Rep Power
    13
    THX for your contributing!!It's great action to anyone developing with java!..
    Being a Code Headman !
  4. #3
  5. Prom night: 1973
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Dec 2001
    Posts
    1,156
    Rep Power
    24
    Try creating a file called javamail.providers with this content
    Code:
    # JavaMail POP3 provider Sun Microsystems, Inc
    protocol=pop3; type=store; class=com.sun.mail.pop3.POP3Store; vendor=Sun Microsy stems, Inc;
    
    # JavaMail SMTP provider Sun Microsystems, Inc
    protocol=smtp; type=transport; class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems, Inc;
    
    # JavaMail IMAP provider Sun Microsystems, Inc
    protocol=imap; type=store; class=com.sun.mail.imap.IMAPStore; vendor=Sun Microsystems, Inc;
    Save it as C:\JBuilder9\jdk1.4\jre\lib\javamail.providers Any difference?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Atlanta
    Posts
    9
    Rep Power
    0

    making progress


    The error now is:

    DEBUG: JavaMail version 1.3.1

    DEBUG: Bad provider entry:

    DEBUG: Bad provider entry:


    This is better!!!
    DEBUG: successfully loaded file: C:\JBuilder9\jdk1.4\jre\lib\javamail.providers

    end result is still an invalid email address! any thoughts there?

    Big help so far! Thanks!!
  8. #5
  9. Prom night: 1973
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Dec 2001
    Posts
    1,156
    Rep Power
    24
    Originally Posted by tboyce
    This is better!!!
    Nah, it's not better at all. I didn't read your debug trace properly, so I thought the file not found part was your error. Looking at the rest of your trace, everything is working fine and it doesn't matter that Java isn't finding the file.

    Your actual error "class javax.mail.SendFailedException: 550 5.7.1 Unable to relay for someone@nowhere.com" is a correct response from your mail server, so Java is probably not the problem. Talk to your email server's admin and see if there's any reason why it won't process your request.

    Try narrowing things down, too. If you're on an internal network, can you send to addresses within it? Are you forbidden from emailing to hotmail/yahoo addresses, or every address?
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Atlanta
    Posts
    9
    Rep Power
    0

    mail server


    when I run the demo (in the javamail demo folder) from the command line, I am able to send an email. I am now sending email to myself (again, this worked in the msgsend.java demo). Incidently, when I copy the msgsend demo code into JBuilder, I get the same failure.

    There is probably a setting in JBuilder that is causing the problem, but I'm not sure what it is. I have run to config JDK and config IDE to import all the jar files in there as well. Maybe I need to take them out as I have it set in my classpath? I am going to try that and see. If you have any other ideas, don't hesitate.

    Tom
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Atlanta
    Posts
    9
    Rep Power
    0

    taking the files out didn't work


    so I put them back...

IMN logo majestic logo threadwatch logo seochat tools logo