Skip to content

Commit d6717b4

Browse files
committed
feat(mail): Prefix SMTP environment variables with APPENGINE_
Prefixed all SMTP-related environment variables (e.g., , ) with to improve namespacing and prevent potential conflicts. The implementation in and the corresponding mocks in have been updated to use the new variable names.
1 parent e5fb462 commit d6717b4

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

api/src/main/java/com/google/appengine/api/mail/MailServiceImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,22 @@ public void send(Message message)
8181

8282
private void sendSmtp(Message message, boolean toAdmin)
8383
throws IllegalArgumentException, IOException {
84-
String smtpHost = envProvider.getenv("SMTP_HOST");
84+
String smtpHost = envProvider.getenv("APPENGINE_SMTP_HOST");
8585
if (smtpHost == null || smtpHost.isEmpty()) {
8686
throw new IllegalArgumentException("SMTP_HOST environment variable is not set.");
8787
}
8888
Properties props = new Properties();
8989
props.put("mail.smtp.host", smtpHost);
90-
props.put("mail.smtp.port", envProvider.getenv("SMTP_PORT"));
90+
props.put("mail.smtp.port", envProvider.getenv("APPENGINE_SMTP_PORT"));
9191
props.put("mail.smtp.auth", "true");
92-
if (Boolean.parseBoolean(envProvider.getenv("SMTP_USE_TLS"))) {
92+
if (Boolean.parseBoolean(envProvider.getenv("APPENGINE_SMTP_USE_TLS"))) {
9393
props.put("mail.smtp.starttls.enable", "true");
9494
}
9595

9696
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
9797
protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
9898
return new javax.mail.PasswordAuthentication(
99-
envProvider.getenv("SMTP_USER"), envProvider.getenv("SMTP_PASSWORD"));
99+
envProvider.getenv("APPENGINE_SMTP_USER"), envProvider.getenv("APPENGINE_SMTP_PASSWORD"));
100100
}
101101
});
102102

@@ -109,7 +109,7 @@ protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
109109
List<InternetAddress> bccRecipients = new ArrayList<>();
110110

111111
if (toAdmin) {
112-
String adminRecipients = envProvider.getenv("ADMIN_EMAIL_RECIPIENTS");
112+
String adminRecipients = envProvider.getenv("APPENGINE_ADMIN_EMAIL_RECIPIENTS");
113113
if (adminRecipients == null || adminRecipients.isEmpty()) {
114114
throw new IllegalArgumentException("Admin recipients not configured.");
115115
}
@@ -251,7 +251,7 @@ private List<InternetAddress> toInternetAddressList(Collection<String> addresses
251251
*/
252252
private void doSend(Message message, boolean toAdmin)
253253
throws IllegalArgumentException, IOException {
254-
if ("true".equals(envProvider.getenv("USE_SMTP_MAIL_SERVICE"))) {
254+
if ("true".equals(envProvider.getenv("APPENGINE_USE_SMTP_MAIL_SERVICE"))) {
255255
sendSmtp(message, toAdmin);
256256
return;
257257
}

api/src/test/java/com/google/appengine/api/mail/MailServiceImplTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ public class MailServiceImplTest {
3636

3737
@Mock private Transport transport;
3838
@Mock private Session session;
39-
@Mock private SystemEnvironmentProvider envProvider;
39+
@Mock private EnvironmentProvider envProvider;
4040

4141
private MailServiceImpl mailService;
4242

4343
@Before
4444
public void setUp() {
4545
mailService = new MailServiceImpl(envProvider);
4646
// Mock environment variables
47-
when(envProvider.getenv("USE_SMTP_MAIL_SERVICE")).thenReturn("true");
48-
when(envProvider.getenv("SMTP_HOST")).thenReturn("smtp.example.com");
49-
when(envProvider.getenv("SMTP_PORT")).thenReturn("587");
50-
when(envProvider.getenv("SMTP_USER")).thenReturn("user");
51-
when(envProvider.getenv("SMTP_PASSWORD")).thenReturn("password");
52-
when(envProvider.getenv("SMTP_USE_TLS")).thenReturn("true");
47+
when(envProvider.getenv("APPENGINE_USE_SMTP_MAIL_SERVICE")).thenReturn("true");
48+
when(envProvider.getenv("APPENGINE_SMTP_HOST")).thenReturn("smtp.example.com");
49+
when(envProvider.getenv("APPENGINE_SMTP_PORT")).thenReturn("587");
50+
when(envProvider.getenv("APPENGINE_SMTP_USER")).thenReturn("user");
51+
when(envProvider.getenv("APPENGINE_SMTP_PASSWORD")).thenReturn("password");
52+
when(envProvider.getenv("APPENGINE_SMTP_USE_TLS")).thenReturn("true");
5353
}
5454

5555
@Test
@@ -507,7 +507,7 @@ public void testSendSmtp_customHeaders() throws IOException, MessagingException
507507
@Test
508508
public void testSendSmtp_disabledTls() throws IOException, MessagingException {
509509
// Setup
510-
when(envProvider.getenv("SMTP_USE_TLS")).thenReturn("false");
510+
when(envProvider.getenv("APPENGINE_SMTP_USE_TLS")).thenReturn("false");
511511
try (MockedStatic<Session> mockedSession = mockStatic(Session.class)) {
512512
ArgumentCaptor<Properties> propsCaptor = ArgumentCaptor.forClass(Properties.class);
513513
mockedSession
@@ -534,7 +534,7 @@ public void testSendSmtp_disabledTls() throws IOException, MessagingException {
534534
@Test
535535
public void testSendSmtp_adminEmail() throws IOException, MessagingException {
536536
// Setup
537-
when(envProvider.getenv("ADMIN_EMAIL_RECIPIENTS"))
537+
when(envProvider.getenv("APPENGINE_ADMIN_EMAIL_RECIPIENTS"))
538538
.thenReturn("admin1@example.com,admin2@example.com");
539539
try (MockedStatic<Session> mockedSession = mockStatic(Session.class)) {
540540
mockedSession.when(() -> Session.getInstance(any(Properties.class), any())).thenReturn(session);
@@ -570,7 +570,7 @@ public void testSendSmtp_adminEmail() throws IOException, MessagingException {
570570
@Test(expected = IllegalArgumentException.class)
571571
public void testSendSmtp_adminEmailNoRecipients() throws IOException, MessagingException {
572572
// Setup
573-
when(envProvider.getenv("ADMIN_EMAIL_RECIPIENTS")).thenReturn(null);
573+
when(envProvider.getenv("APPENGINE_ADMIN_EMAIL_RECIPIENTS")).thenReturn(null);
574574

575575
// Create a simple message
576576
MailService.Message message = new MailService.Message();
@@ -627,7 +627,7 @@ public void testSendSmtp_connectionFailure() throws IOException, MessagingExcept
627627
@Test(expected = IllegalArgumentException.class)
628628
public void testSendSmtp_missingSmtpHost() throws IOException, MessagingException {
629629
// Setup
630-
when(envProvider.getenv("SMTP_HOST")).thenReturn(null);
630+
when(envProvider.getenv("APPENGINE_SMTP_HOST")).thenReturn(null);
631631

632632
// Create a simple message
633633
MailService.Message message = new MailService.Message();

0 commit comments

Comments
 (0)