[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:
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();
}
}