This is a bridge between Exchange web services java API and JavaMail API This is a fork of org.sourceforge.net.javamail4ews You will need the EWS url to connect, something like https://owa.example.com/ews/exchange.asmx and maybe a username and password
- Java 21 or higher (LTS recommended)
- Maven 3.6.0 or higher
- Access to Microsoft Exchange Web Services
This project has been upgraded with recent dependencies and Java 21 compatibility:
- Migrated from javax.mail to Jakarta Mail API 2.1.1
- Updated to Java 21 (from Java 8)
- Upgraded all Maven plugins to latest versions
- Resolved security vulnerabilities in dependencies
- Improved performance and maintainability
See MIGRATION_GUIDE.md for detailed upgrade information.
This project uses GitHub Actions for continuous integration and deployment:
- CI Pipeline: Runs on every push and pull request, testing against Java 17 and 21
- Release Pipeline: Automatically deploys tagged releases to GitHub Packages
- Workflow Validation: Weekly validation of CI/CD setup
See GITHUB_ACTIONS_MIGRATION_GUIDE.md for detailed information about the CI/CD setup.
//Initalize a session
Session session = Session.getInstance(new Properties());
//Get the EWS store implementation
Store store = session.getStore("ewsstore");
//Connect to the Exchange server - No port required.
//Also connect() might be used if the session is initalized with the known mail.* properties
store.connect("https://example.com/ews/exchange.asmx",
"[email protected]",
"password");
Folder folder = store.getDefaultFolder();
folder.open(Folder.READ_ONLY);
Message[] messages = folder.getMessages();
//Initalize a session
Session session = Session.getInstance(new Properties());
//Get the EWS transport implementation
Transport lTransport = session.getTransport("ewstransport");
//Connect to the Exchange server - No port required.
//Also connect() might be used if the session is initalized with the known mail.* properties
lTransport.connect("https://example.com/ews/exchange.asmx",
"[email protected]",
"password");
//Create a message as before
Message lMessage = new MimeMessage(session);
lMessage.setRecipient(RecipientType.TO, new InternetAddress("[email protected]"));
lMessage.setSubject("Hello World!");
lMessage.setText("Hello World!");
//Send the mail via EWS
lTransport.sendMessage(lMessage, lMessage.getRecipients(RecipientType.TO));
The mailsample
module provides a working example:
# Build the sample
cd mailsample
mvn clean compile
# Run the sample (requires EWS configuration)
mvn exec:java -Dexec.mainClass="org.gartcimore.java.mailsample.MailSample"
Create a properties file or set system properties:
# EWS server configuration
mail.ewsstore.server=https://owa.example.com/ews/exchange.asmx
mail.ewsstore.username[email protected]
mail.ewsstore.password=your-password
# Optional: Trust all certificates (for testing only)
mail.ewsstore.trustall=true
Properties props = new Properties();
props.setProperty("mail.store.protocol", "ewsstore");
props.setProperty("mail.transport.protocol", "ewstransport");
props.setProperty("mail.ewsstore.server", "https://owa.example.com/ews/exchange.asmx");
Session session = Session.getInstance(props);
Ensure you have Java 21+ and Maven 3.6+ installed:
java -version # Should show Java 21 or higher
mvn -version # Should show Maven 3.6.0 or higher
# Clean build with all tests
mvn clean compile test
# Build without tests
mvn clean compile -DskipTests
# Package the JAR
mvn clean package
mvn clean test
mvn clean test -Pbaseline-tests
mvn clean test -Pperformance-tests
After upgrading from an older version, run these commands to verify everything works:
# 1. Verify compilation with Java 21
mvn clean compile
# 2. Run baseline tests to ensure core functionality
mvn clean test -Pbaseline-tests
# 3. Check for dependency issues
mvn dependency:analyze
# 4. Run security scan (optional)
mvn org.owasp:dependency-check-maven:check