Results 1 to 9 of 9
  1. #1
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    307
    Rep Power
    6

    Default [SOLVED] JavaMail on AS400 Authentication error

    Hello, I'm currently developing a mail client that will simply allow me to connect to a mail server from an AS400 system and send mail.

    The problem I'm having is when a mail server requires authentication, when the program is run on the AS400, some of the properties I'm setting seem to be being ignored, such as the "mail.smtp.auth". This is preventing me from authenticating.

    If anybody has any ideas I'm all for them, I've been working on this for a couple days now.

    Here is the basic outline of the code:

    Java Code:
            private static final String SMTP_HOST_NAME = "smtp.aol.com";
    	private static final String LOGON = "*****";
    	private static final String PASSWORD = "*****";
    	private static final String ADDRESS = "*****@aol.com";
    
            public static void sendMessage() {
    		PrintStream ps=null;
    		
    		 try {
    		    //2. Redirect standard-output to log file (closed at end of this method)
                IFSFileOutputStream fod = new IFSFileOutputStream(AS400Utilities.getAS400(),"/home/cybra/cybrajavaclasses6/email.log");
                ps = new PrintStream(fod);
                System.setOut(ps);
                System.setErr(ps);
    		} catch (AS400SecurityException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            } 
            
            System.out.println(System.getProperties());
    
    		Properties props = new Properties();
    		props.put("mail.transport.protocol", "smtp");
    		props.put("mail.smtp.host", SMTP_HOST_NAME);
    		props.put("mail.smtp.auth", "true");
    		props.put("mail.debug", "true");
    //		props.put("mail.smtp.starttls.enable", "true");
    
    		System.out.println("Obtaining Session");
    		Session session = Session.getDefaultInstance(props,
    				new javax.mail.Authenticator() {
    					protected PasswordAuthentication getPasswordAuthentication() {
    						return new PasswordAuthentication(LOGON, PASSWORD);
    					}
    				});
    		System.out.println("Session Obtained: " + session);
    		session.setDebug(true);
    
    		System.out.println("Obtaining Message");
    		Message msg = new MimeMessage(session);
    		System.out.println("Message Obtained");
    		try {
    			System.out.println("Adding From");
    			InternetAddress addressFrom = new InternetAddress(ADDRESS);
    			msg.setFrom(addressFrom);
    			
    			System.out.println("Adding To");
    			InternetAddress addressTo = new InternetAddress("tbudzinski@cybra.com");
    			msg.setRecipient(Message.RecipientType.TO, addressTo);
    			
    			System.out.println("Adding Text");
    			msg.setSubject("This is the Subject");
    			msg.setContent("This is a test Message", "text/plain");
    			
    			System.out.println("Obtaining Transport");
    			Transport trans = session.getTransport("smtp");
    			System.out.println("Transport Obtained: " + trans);
    
    //			Transport.send(msg);
    			System.out.println("Connecting Transport");
    			trans.connect();
    			System.out.println("Transport Connected: " + trans.isConnected());
    			
    			System.out.println("Sending Message");
    			trans.sendMessage(msg, msg.getAllRecipients());
    			System.out.println("Message Sent");
    			
    			trans.close();
    		} catch (Throwable e){
    			e.printStackTrace();
    		}
    }

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    I've done quite bit of Java on the 400, and I seldom had any problems. My best trick was running Tomcat (not the one that comes with OS/400). Anyway, I assume your code works when you run off your PC, but then fails on the 400.

    One thing I did is this. I never compiled anything on the 400. I just copied .class files to the IFS. Are you taking that approach?

  3. #3
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    307
    Rep Power
    6

    Default

    Thanks for the reply,

    Actually this is just a minor part of a larger program that we distribute. We jar our files and there's a RPG side that will call it when its needed.

    The thing works fine from the PC.

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    I guess that answers my question. I don't believe that OS/400 itself has anything to do with your mail transmission. I noticed you had tls commented out. I know G-Mail requires it; I don't know about AOL. Have you checked the Java PTF's? Possibly, there is a fix for TLS in Java that is leading to your problem...

  5. #5
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    307
    Rep Power
    6

    Default

    I commented that out because on the pc side it was irrelevant.

    I've already tried with that line in the program but it seems to be suffering from being ignored just like the mail.smtp.auth property.

    I've already spent a good while looking for anything online about this, which is why I finally decided to make this thread hoping someone else might have encountered this or see a problem with my code.

    I'll just have to keep at it.

  6. #6
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    I forgot to mention before that the problem could be with the version of javamail on the 400.

    Here is a link to JavaMail. You might try using the JAR from the site, first on your PC and then on the 400.

    Whatever is wrong, it's not that Java is running on the AS/400; it's that something is missing from the 400's Java environment. BTW, what version of Java are you using on the 400? Is it the same as your PC?

  7. #7
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    307
    Rep Power
    6

    Default

    Both are running Java 1.4

    The jar's on both system are exactly the same as I copied them directly from my PC onto the AS400

  8. #8
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Well, it sounds as if you have been thorough... I'm out of ideas...

  9. #9
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    307
    Rep Power
    6

    Default

    Thanks for the help, I've been able to clear up the main problem I was having.

    I had to place the jar directly into the jdk/lib/ext folder for it to take hold.

    Apparently there's an older jar file somewhere on the system that was interfering with mine and even though the first couple of lines looked like it was coming from my jar, mainly

    DEBUG: setDebug: JavaMail version 1.4ea

    The rest of the debug code came from a version lower then 1.3 where authentication was yet to be implemented.

Similar Threads

  1. [SOLVED] JavaMail Authentication Problem
    By frost750 in forum New To Java
    Replies: 1
    Last Post: 02-06-2009, 05:02 PM
  2. javamail exception: 557 mail head error
    By allanwakes in forum Java Servlet
    Replies: 2
    Last Post: 10-02-2008, 12:05 PM
  3. error 530 error authentication required
    By rgale in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-12-2008, 05:28 PM
  4. 530 5.7.0 Authentication Required - JavaMail gmail
    By simon in forum Advanced Java
    Replies: 1
    Last Post: 07-15-2007, 12:52 AM
  5. JavaMail:Authentication required error
    By bbq in forum Advanced Java
    Replies: 1
    Last Post: 07-05-2007, 05:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •