Skip to content

Commit 2757097

Browse files
authored
Merge pull request #2589 from hongwei1/feature/replaceLiftMail
refactor/replace lift mail
2 parents 821ebf9 + 3161b5f commit 2757097

11 files changed

Lines changed: 495 additions & 107 deletions

File tree

‎obp-api/pom.xml‎

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@
101101
<artifactId>commons-text</artifactId>
102102
<version>1.10.0</version>
103103
</dependency>
104+
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-email -->
105+
<dependency>
106+
<groupId>org.apache.commons</groupId>
107+
<artifactId>commons-email</artifactId>
108+
<version>1.5</version>
109+
</dependency>
104110
<dependency>
105111
<groupId>org.postgresql</groupId>
106112
<artifactId>postgresql</artifactId>
@@ -178,6 +184,11 @@
178184
<artifactId>httpclient</artifactId>
179185
<version>4.5.13</version>
180186
</dependency>
187+
<dependency>
188+
<groupId>org.apache.commons</groupId>
189+
<artifactId>commons-pool2</artifactId>
190+
<version>2.11.1</version>
191+
</dependency>
181192
<dependency>
182193
<groupId>org.eclipse.jetty</groupId>
183194
<artifactId>jetty-util</artifactId>
@@ -661,24 +672,25 @@
661672
<release>${java.version}</release>
662673
</configuration>
663674
</plugin>
664-
<plugin>
665-
<groupId>org.scalaxb</groupId>
666-
<artifactId>scalaxb-maven-plugin</artifactId>
667-
<version>1.7.5</version>
668-
<configuration>
669-
<packageName>code.adapter.soap</packageName>
670-
<wsdlDirectory>src/main/resources/custom_webapp/wsdl</wsdlDirectory>
671-
<xsdDirectory>src/main/resources/custom_webapp/xsd</xsdDirectory>
672-
</configuration>
673-
<executions>
674-
<execution>
675-
<id>scalaxb</id>
676-
<goals>
677-
<goal>generate</goal>
678-
</goals>
679-
</execution>
680-
</executions>
681-
</plugin>
675+
<!--soap related plugin begin-->
676+
<!-- <plugin>-->
677+
<!-- <groupId>org.scalaxb</groupId>-->
678+
<!-- <artifactId>scalaxb-maven-plugin</artifactId>-->
679+
<!-- <version>1.7.5</version>-->
680+
<!-- <configuration>-->
681+
<!-- <packageName>code.adapter.soap</packageName>-->
682+
<!-- <wsdlDirectory>src/main/resources/custom_webapp/wsdl</wsdlDirectory>-->
683+
<!-- <xsdDirectory>src/main/resources/custom_webapp/xsd</xsdDirectory>-->
684+
<!-- </configuration>-->
685+
<!-- <executions>-->
686+
<!-- <execution>-->
687+
<!-- <id>scalaxb</id>-->
688+
<!-- <goals>-->
689+
<!-- <goal>generate</goal>-->
690+
<!-- </goals>-->
691+
<!-- </execution>-->
692+
<!-- </executions>-->
693+
<!-- </plugin>-->
682694
<!--grpc related plugin begin-->
683695
<!-- currently not need, enable this plugin when need generate new grpc code.
684696
<plugin>

‎obp-api/src/main/resources/props/sample.props.template‎

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,70 @@ dev.port=8080
270270
#Default value is obp (very highly recomended)
271271
apiPathZero=obp
272272

273-
## Sending mail out
274-
## Not need in dev mode, but important for production
275-
mail.api.consumer.registered.sender.address=no-reply@example.com
276-
mail.api.consumer.registered.notification.addresses=you@example.com
277-
## Not need in dev mode, but important for production
278-
## We send an email after any exception
279-
# mail.exception.sender.address=no-reply@example.com
280-
# mail.exception.registered.notification.addresses=notify@example.com,notify2@example.com,notify3@example.com
281-
# This property allows sending API registration data to developer's email.
282-
#mail.api.consumer.registered.notification.send=false
283-
We only send consumer keys and secret if this is true
284-
#mail.api.consumer.registered.notification.send.sensistive=false
273+
## Email Configuration (CommonsEmailWrapper)
274+
## ===========================================
275+
##
276+
## This section configures email sending using CommonsEmailWrapper instead of Lift Mailer.
277+
## All email functionality (password reset, validation, notifications) now uses these settings.
278+
##
279+
## SMTP Server Configuration
280+
## -------------------------
281+
## Basic SMTP settings
285282
mail.smtp.host=127.0.0.1
286283
mail.smtp.port=25
284+
mail.smtp.auth=false
285+
mail.smtp.user=
286+
mail.smtp.password=
287+
288+
## TLS/SSL Configuration
289+
## ---------------------
290+
## Enable STARTTLS (recommended for most SMTP servers)
291+
mail.smtp.starttls.enable=false
292+
## Enable SSL (use with port 465)
293+
mail.smtp.ssl.enable=false
294+
## TLS protocols to use (recommended: TLSv1.2)
295+
mail.smtp.ssl.protocols=TLSv1.2
296+
## Trust all certificates (for development only)
297+
#mail.smtp.ssl.trust=*
298+
299+
## Debug Configuration
300+
## ------------------
301+
## Enable email debugging (shows SMTP communication)
302+
mail.debug=false
303+
304+
## Email Sender Configuration
305+
## -------------------------
306+
## Default sender address for all emails
307+
mail.users.userinfo.sender.address=no-reply@example.com
308+
309+
## Consumer Registration Email
310+
## --------------------------
311+
## Enable/disable consumer registration notifications
312+
mail.api.consumer.registered.notification.send=false
313+
## Sender address for consumer registration emails
314+
mail.api.consumer.registered.sender.address=no-reply@example.com
315+
## Recipient addresses for consumer registration notifications (comma-separated)
316+
mail.api.consumer.registered.notification.addresses=you@example.com
317+
## Send sensitive information (consumer keys/secrets) via email
318+
mail.api.consumer.registered.notification.send.sensistive=false
319+
320+
## Exception Notification Email
321+
## ---------------------------
322+
## Sender address for exception notifications
323+
mail.exception.sender.address=no-reply@example.com
324+
## Recipient addresses for exception notifications (comma-separated)
325+
mail.exception.registered.notification.addresses=notify@example.com,notify2@example.com,notify3@example.com
326+
327+
## Tesobe Mail Server:
328+
## mail.smtp.host=mail.tesobe.com
329+
## mail.smtp.port=25
330+
## mail.smtp.auth=true
331+
## mail.smtp.user=your-email@tesobe.com
332+
## mail.smtp.password=your-password
333+
## mail.smtp.starttls.enable=true
334+
## mail.smtp.ssl.enable=false
335+
## mail.smtp.ssl.protocols=TLSv1.2
336+
287337

288338
## Oauth token timeout
289339
token_expiration_weeks=4

‎obp-api/src/main/scala/bootstrap/liftweb/Boot.scala‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import code.api.util.ApiRole.CanCreateEntitlementAtAnyBank
4646
import code.api.util.ErrorMessages.MandatoryPropertyIsNotSet
4747
import code.api.util._
4848
import code.api.util.migration.Migration
49+
import code.api.util.CommonsEmailWrapper
4950
import code.api.util.migration.Migration.DbFunction
5051
import code.apicollection.ApiCollection
5152
import code.apicollectionendpoint.ApiCollectionEndpoint
@@ -151,7 +152,6 @@ import org.apache.commons.io.FileUtils
151152
import java.io.{File, FileInputStream}
152153
import java.util.stream.Collectors
153154
import java.util.{Locale, TimeZone}
154-
import javax.mail.internet.MimeMessage
155155
import scala.concurrent.ExecutionContext
156156

157157
/**
@@ -693,10 +693,6 @@ class Boot extends MdcLoggable {
693693
case e: ExceptionInInitializerError => logger.warn(s"BankAccountCreationListener Exception: $e")
694694
}
695695

696-
Mailer.devModeSend.default.set( (m : MimeMessage) => {
697-
logger.info("Would have sent email if not in dev mode: " + m.getContent)
698-
})
699-
700696
LiftRules.exceptionHandler.prepend{
701697
case(_, r, e) if e.isInstanceOf[NullPointerException] && e.getMessage.contains("Looking for Connection Identifier") => {
702698
logger.error(s"Exception being returned to browser when processing url is ${r.request.uri}, method is ${r.request.method}, exception detail is $e", e)
@@ -880,7 +876,7 @@ class Boot extends MdcLoggable {
880876
}
881877

882878
private def sendExceptionEmail(exception: Throwable): Unit = {
883-
import Mailer.{From, PlainMailBodyType, Subject, To}
879+
884880
import net.liftweb.util.Helpers.now
885881

886882
val outputStream = new java.io.ByteArrayOutputStream
@@ -899,18 +895,18 @@ class Boot extends MdcLoggable {
899895

900896
//technically doesn't work for all valid email addresses so this will mess up if someone tries to send emails to "foo,bar"@example.com
901897
val to = toAddressesString.split(",").toList
902-
val toParams = to.map(To(_))
903-
val params = PlainMailBodyType(error) :: toParams
904-
905-
//this is an async call
906-
Mailer.sendMail(
907-
From(from),
908-
Subject(s"you got an exception on $host"),
909-
params :_*
898+
899+
val emailContent = CommonsEmailWrapper.EmailContent(
900+
from = from,
901+
to = to,
902+
subject = s"you got an exception on $host",
903+
textContent = Some(error)
910904
)
905+
906+
//this is an async call∆∆
907+
CommonsEmailWrapper.sendTextEmail(emailContent)
911908
}
912909

913-
//if Mailer.sendMail wasn't called (note: this actually isn't checking if the mail failed to send as that is being done asynchronously)
914910
if(mailSent.isEmpty)
915911
logger.warn(s"Exception notification failed: $mailSent")
916912
}

0 commit comments

Comments
 (0)