The following gmail program runs on PC without any problem but failed to run on AS400. I get "certificate container *SYSTEM could not be accessed" error.
To solve this problem. Start HTTP admin on port 2001. In
Digital Certificate Manager use
Create New Certificate Store to create a certificate for *SYSTEM. 2 files are created:
/QIBM/userdata/ICSS/Cert/Server/default.rdb
/QIBM/userdata/ICSS/Cert/Server/default.kdb
Change their object authorities to *RWX
That's it.
When creating the certificate I was given a Certificate Request which I did not have to use:
he certificate request data is shown below. Copy and paste the request data, including both the Begin request and End request lines, into the form that the Certificate Authority (CA) provided.
Warning: If you exit this page, the certificate request data is lost. Therefore, make sure you carefully copy and paste the data into the Certificate Authority (CA) form or into a file for later use.
-----BEGIN NEW CERTIFICATE REQUEST-----
MIIBjTCB9wIBADBOMQswCQYDVQQGEwJVUzERMA8GA1UECBMIaWxsaW5vaXMxEDAO
BgNVBAcTB2xvbWJhcmQxDDAKBgNVBAoTA21yYzEMMAoGA1UEAxMDbXJjMIGfMA0G
CSqGSIb3DQEBAQUAA4GNADCBiQKBgQCjTKF+oI03RpufNRDaM/9MvQlfOIp02uFG
QHPnuYieahMZ3xaXnatXzSXrT54dxUhRpVXixD1YdDygQyOzRt7YXAV3zsS4a8i1
ydGaN9hezU/UwLZjEoHGlPYIusQQhkxUiG5VKdPvqIZ7Xo/2amCVGr7VJVMZJg2b
E0RKB4ZCFQIDAQABoAAwDQYJKoZIhvcNAQEEBQADgYEAgmlPk//8FE2Rr/HcnLuQ
2whtyrKGd6aeNTTJ1DI4ic/CZwVzYsB2gLgz3+xlgfuWWYe023vJDzX8SXnyjZw2
lk7MZIsqZpuKQebLvSOMYACMWWA+UqkuxUX0Y1a+9NQ6JKwFlAAKTWOCmCx6IPD8
690VjDqnAW7gZ5L6kw5QTas=
-----END NEW CERTIFICATE REQUEST-----
package testmail;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class GMail {
String emailHost = "smtp.gmail.com";
String portNumber = "465";
String from = "bruce@mrc-productivity.com";
String pswd = "password";
String to = "bruce@mrc-productivity.com";
String subj = "emai subject";
String text = "email text is here.";
public GMail() {
Properties props = new Properties();
props.put("mail.smtp.user", from);
props.put("mail.smtp.host", emailHost);
props.put("mail.smtp.port", portNumber);
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", portNumber);
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
//SecurityManager security = System.getSecurityManager();
try {
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setText(text);
msg.setSubject(subj);
msg.setFrom(new InternetAddress(from));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
Transport.send(msg);
} catch (Exception mex) {
mex.printStackTrace();
}
System.out.println("Done.");
}
public static void main(String[] args) {
new GMail();
}
private class SMTPAuthenticator extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from, pswd);
}
}
}