Java Apache to Office 365
"Versfelt, Charles via JAVA400-L" <[email protected]> Mon, 17 Nov 2025 18:23:01 +0000
| Newsgroups | gmane.comp.lang.as400.java |
|---|---|
| Message-ID | <PH7PR08MB8426612B26D39A28A08D53C7C3C9A@PH7PR08MB8426.namprd08.prod.outlook.com> |
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.