RE: Java Apache to Office 365
Richard Schoen <richard-DiTrGpQEJGItADg8e/3/[email protected]> Mon, 17 Nov 2025 23:01:42 +0000
| Newsgroups | gmane.comp.lang.as400.java |
|---|---|
| Message-ID | <CH0PR12MB5250C7F9836B11742ACA7CFAB7C9A@CH0PR12MB5250.namprd12.prod.outlook.com> |
Are you using the JavaMail jar file and a Java or RPG program ? I guess if you're using RUNJVA you're creating a Java program. First I would never use RUNJVA. Use something like the QSH command to run = your Java or something like the QSHEXEC command in my QShell on I open sour= ce utility. You can then actually capture a Java return code error as well = as STDOUT which is Java command line logging. Word has it that Basic Auth is going away in 2026 so you may want to actual= ly start looking in to using MS Graph and OAuth2. Or you could look into cr= eating an Exchange SMTP Connector which will allow your team to use port 25= to still send unauthenticated emails via TLS on Port 25 from your public I= P address. There is some Office365 config required as well as you need to c= reate an Exchange Connector. Might want to upgrade your Java version unless you're on an old IBMi. Mini= mally 1.8 would be a good idea. Regards, Richard Schoen Web:=A0http://www.richardschoen.net Email:=A0richard-DiTrGpQEJGItADg8e/3/[email protected] -----Original Message----- Today's Topics: 1. Java Apache to Office 365 (Versfelt, Charles via JAVA400-L) ---------------------------------------------------------------------- message: 1 date: Mon, 17 Nov 2025 18:23:01 +0000 from: "Versfelt, Charles via JAVA400-L" <[email protected]> subject: Java Apache to Office 365 Hi, I'm fairly inexperienced in java, I'm mainly an old-school RPG programmer. We have several Java programs that send e-mails, some with and some without= attachments, using Apache commons. I'm somewhat familiar with the programs. Our IBMi is on java version "1.6.= 0" We're switching our e-mail to office 365. I've gone through the same change with a number of Visual Basic programs, a= nd now I'm trying to address the IBMi Java programs. The changes I had to make in my Visual Basic programs are these: 1. The host has to change to smtp.office365.com 2. SSL has to be enabled. 3. The port used has to be 587. 4. I have to force TSL 1.2 security level. In Visual Basic, to force TSL 1.2, I had to use command ServicePointManager= .SecurityProtocol =3D SecurityProtocolType.Tls12 >From the searching I did online, I found some websites talking about sendi= ng office 365 e-mails in Java, but not a lot specific to Apache Commons. As I said, I don't want to rewrite the programs if I can avoid it. As far as I can tell from what I saw online, if all I need is what I change= d in my VB.net programs, I can change these in my Apache Commons Java E-mai= l programs like this: 1. email.setHostName("smtp.office365.com"); 2. email.setSSLOnConnect(true); 3. email.setSmtpPort(587); 4. System.setProperty("mail.transport.protocol", "smtps"); System.setProper= ty("mail.smtps.ssl.protocols", "TLSv1.2"); So my program looks like this, passwords and e-mails masked. HtmlEmail email =3D new HtmlEmail (); //email.setHostName("exchange.postoffice.net"); System.setProperty("mail.transport.protocol", "smtps"); System.setProperty(= "mail.smtps.ssl.protocols", "TLSv1.2"); email.setHostName("smtp.office365.c= om"); email.setSmtpPort(587); email.setSSLOnConnect(true); (everything below is original) try { email.setFrom("[email protected]", "Me"); email.setAuthenticator(new DefaultAuthenticator("[email protected]" "xxx")); } ca= tch (EmailException e1) { CleanUp(); } When I test this program from the c= ommand line RUNJVA, the program says Java program completed, but no e-mail = arrives. As far as I can tell it's not encountering any errors. It's just not sendi= ng an e-mail. Am I missing something? Thanks for your help. Charles Versfelt -- = This is the Java Programming on and around the IBM i (JAVA400-L) mailing li= st To post a message email: [email protected] To subscribe, unsubscribe, or change list options, visit: https://lists.midrange.com/mailman/listinfo/java400-l or email: JAVA400-L-request-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org Before posting, please take a moment to review the archives at https://archive.midrange.com/java400-l.