garydgregory commented on code in PR #354:
URL: https://github.com/apache/commons-email/pull/354#discussion_r2230874110
##########
commons-email2-jakarta/src/test/java/org/apache/commons/mail2/jakarta/EmailTest.java:
##########
@@ -571,6 +572,17 @@ public void testGetSetAuthentication() {
assertEquals(strPassword,
retrievedAuth.getPasswordAuthentication().getPassword());
}
+ @Test
+ public void testSetOAuth2Required() throws EmailException {
+ email.setHostName(strTestMailServer);
+ email.setOAuth2Required(true);
+ final Session mailSession = email.getMailSession();
+
+ // tests
+ assertNotNull(mailSession);
+ assertEquals("XOAUTH2",
mailSession.getProperties().getProperty("mail.smtp.auth.mechanisms"));
Review Comment:
Reuse `EmailConstants`.
##########
commons-email2-javax/src/main/java/org/apache/commons/mail2/javax/Email.java:
##########
@@ -822,6 +827,10 @@ public Session getMailSession() throws EmailException {
properties.setProperty(EmailConstants.MAIL_SMTP_AUTH, "true");
}
+ if (isOAuth2Required()) {
+ properties.put(EmailConstants.MAIL_SMTP_AUTH_MECHANISMS,
"XOAUTH2");
Review Comment:
Refactor `"XOAUTH2"` into a constant.
##########
commons-email2-core/src/main/java/org/apache/commons/mail2/core/EmailConstants.java:
##########
@@ -56,6 +56,9 @@ public final class EmailConstants {
/** If set to true, tries to authenticate the user using the AUTH command.
*/
public static final String MAIL_SMTP_AUTH = "mail.smtp.auth";
+ /** If set to true, tries to authenticate the user using an OAuth2 token.
*/
+ public static final String MAIL_SMTP_AUTH_MECHANISMS =
"mail.smtp.auth.mechanisms";
Review Comment:
The Javadoc since tag is missing.
##########
commons-email2-javax/src/test/java/org/apache/commons/mail2/javax/EmailTest.java:
##########
@@ -571,6 +572,17 @@ public void testGetSetAuthentication() {
assertEquals(strPassword,
retrievedAuth.getPasswordAuthentication().getPassword());
}
+ @Test
+ public void testSetOAuth2Required() throws EmailException {
+ email.setHostName(strTestMailServer);
+ email.setOAuth2Required(true);
+ final Session mailSession = email.getMailSession();
+
+ // tests
+ assertNotNull(mailSession);
+ assertEquals("XOAUTH2",
mailSession.getProperties().getProperty("mail.smtp.auth.mechanisms"));
Review Comment:
Reuse `EmailConstants`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]