Re: Java Apache to Office 365
Colin Williams <[email protected]> Tue, 18 Nov 2025 07:29:20 +0000
| Newsgroups | gmane.comp.lang.as400.java |
|---|---|
| Message-ID | <CAJOH7P03e-Wn_DMpC9QiiJJRpZ1zCjoMArSW+Cary0+_pRXQ-A@mail.gmail.com> |
If you are enabling ssl the client will need to look up the servers certificate that it presents in its keystore to confirm if it can trust it. If a keystore isn't specified its probably using the default one in the security folder (cacerts) or could be using the ibmi dcm. Either way the keystore will need a copy of the server certificate of the server its connecting to or the ssl handshake will fail. Add -Djavax.net.debug=all to your startup command for the java which should dump the ssl handshake and somewhere in there it will show you the certificate its looking for and whether it found it or not. Cheers Colin On Mon, 17 Nov 2025, 18:23 Versfelt, Charles via JAVA400-L, < [email protected]> wrote: > 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, > and 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 = SecurityProtocolType.Tls12 > > From the searching I did online, I found some websites talking about > sending 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 > changed in my VB.net programs, I can change these in my Apache Commons Java > E-mail 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.setProperty("mail.smtps.ssl.protocols", "TLSv1.2"); > > So my program looks like this, passwords and e-mails masked. > > HtmlEmail email = 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.com"); > email.setSmtpPort(587); > email.setSSLOnConnect(true); > (everything below is original) > try { > email.setFrom("[email protected]", "Me"); > email.setAuthenticator(new DefaultAuthenticator("[email protected]" "xxx")); > } catch (EmailException e1) { > CleanUp(); > } > When I test this program from the command 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 > sending 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 > list > 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. > -- This is the Java Programming on and around the IBM i (JAVA400-L) mailing list 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.