Send mail to gepafin or sviluppumbria based on hub email
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
package net.gepafin.tendermanagement.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.mailgun.api.v3.MailgunMessagesApi;
|
||||
import com.mailgun.client.MailgunClient;
|
||||
|
||||
@Component
|
||||
public class MailUtil {
|
||||
|
||||
@Value("${apiKey}")
|
||||
private String apiKeyValue;
|
||||
|
||||
@Value("${mailGun_user}")
|
||||
private String mailGunUser;
|
||||
|
||||
@Value("${mailGun_apiKey}")
|
||||
private String mailGunApiKey;
|
||||
|
||||
@Value("${mailGun_domainName}")
|
||||
private String mailGunDomainName;
|
||||
|
||||
@Value("${mailGun_base_url}")
|
||||
private String mailGunBaseUrl;
|
||||
|
||||
@Value("${isMailSendingEnabled}")
|
||||
private String isEmailSendingEnabled;
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
public Boolean isTestProfileActivated() {
|
||||
String[] activeProfiles = environment.getActiveProfiles();
|
||||
return Arrays.stream(activeProfiles).anyMatch("test"::equals);
|
||||
}
|
||||
|
||||
public void sendMailByMailGunAPI(List<String> recipents, List<String> CC, List<String> BCC, String subject,
|
||||
String body, String replyTo) {
|
||||
if (Boolean.FALSE.equals(Boolean.parseBoolean(isEmailSendingEnabled))) {
|
||||
return;
|
||||
}
|
||||
|
||||
MailgunMessagesApi mailgunMessagesApi = MailgunClient.config(mailGunBaseUrl, mailGunApiKey)
|
||||
.createApi(MailgunMessagesApi.class);
|
||||
|
||||
String mailFrom = mailGunUser;
|
||||
|
||||
com.mailgun.model.message.Message.MessageBuilder temp = com.mailgun.model.message.Message.builder()
|
||||
.replyTo(replyTo).from(mailFrom).to(recipents).subject(subject).html(body);
|
||||
|
||||
if (Boolean.FALSE.equals(CollectionUtils.isEmpty(CC))) {
|
||||
temp.cc(CC);
|
||||
}
|
||||
|
||||
if (Boolean.FALSE.equals(CollectionUtils.isEmpty(BCC))) {
|
||||
temp.bcc(BCC);
|
||||
}
|
||||
|
||||
if (Boolean.FALSE.equals(isTestProfileActivated())) {
|
||||
com.mailgun.model.message.Message message = temp.build();
|
||||
mailgunMessagesApi.sendMessage(mailGunDomainName, message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void sendByMailGun(String subject, String body, List<String> receiverEmails, String replyTo) {
|
||||
sendMailByMailGunAPI(receiverEmails, null, null, subject, body, replyTo);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user