-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
569d484
commit b0c2a2f
Showing
3 changed files
with
21 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
package services | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import com.sendgrid.{Method, Request, SendGrid} | ||
import com.sendgrid.helpers.mail.Mail | ||
import com.sendgrid.helpers.mail.objects.{Email, Personalization} | ||
import com.typesafe.config.{Config, ConfigFactory} | ||
import models.InventoryTemplateTopLevel | ||
import shared.AppFunctions.objectMapper | ||
|
||
import javax.inject.{Inject, Singleton} | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
@@ -49,31 +46,6 @@ class EmailService @Inject()()(implicit ec: ExecutionContext) { | |
} | ||
} | ||
|
||
def sendEmailWithStringData(to: String, templateId: String, dynamicData: InventoryTemplateTopLevel): Future[Unit] = Future { | ||
val from = new Email("[email protected]") | ||
val toEmail = new Email(to) | ||
val mail = new Mail() | ||
mail.setFrom(from) | ||
mail.setTemplateId(templateId) | ||
|
||
val personalization = new Personalization() | ||
personalization.addTo(toEmail) | ||
|
||
val jsonData: JsonNode = objectMapper.valueToTree(dynamicData) | ||
personalization.addDynamicTemplateData("vehicles", jsonData) | ||
mail.addPersonalization(personalization) | ||
|
||
val request = new Request() | ||
request.setMethod(Method.POST) | ||
request.setEndpoint("mail/send") | ||
request.setBody(mail.build()) | ||
|
||
val response = sendGridClient.api(request) | ||
if (response.getStatusCode >= 400) { | ||
throw new Exception(s"Failed to send email: ${response.getBody}") | ||
} | ||
} | ||
|
||
def removeEmailFromGlobalUnsubscribe(email: String): Future[Unit] = Future { | ||
val request = new Request() | ||
request.setMethod(Method.DELETE) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters