mail plugin
This commit is contained in:
commit
87cd3204c2
4 changed files with 68 additions and 28 deletions
5
doc/MAIL.md
Normal file
5
doc/MAIL.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Mail
|
||||||
|
|
||||||
|
Testen von Mailing kann man über
|
||||||
|
|
||||||
|
https://www.mail-tester.com/
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
https://techcommunity.microsoft.com/t5/exchange/javamail-connecting-to-office-365-xoauth2-for-imap/m-p/1505026
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package com.alexanderlogistics.mail;
|
package com.alexanderlogistics.mail;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||||
|
import org.imixs.marty.profile.ProfileService;
|
||||||
import org.imixs.workflow.ItemCollection;
|
import org.imixs.workflow.ItemCollection;
|
||||||
import org.imixs.workflow.exceptions.PluginException;
|
import org.imixs.workflow.exceptions.PluginException;
|
||||||
|
|
||||||
|
|
@ -24,8 +26,12 @@ public class MailPlugin extends org.imixs.marty.profile.MailPlugin {
|
||||||
@ConfigProperty(name = "mail.authenticatedSender")
|
@ConfigProperty(name = "mail.authenticatedSender")
|
||||||
Optional<String> mailAuthenticatedSender;
|
Optional<String> mailAuthenticatedSender;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ProfileService profileService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method adds the attachments of the blob workitem to the MimeMessage
|
* This method creates a new mail header with custom from and reply-to addresses
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ItemCollection run(ItemCollection documentContext, ItemCollection documentActivity) throws PluginException {
|
public ItemCollection run(ItemCollection documentContext, ItemCollection documentActivity) throws PluginException {
|
||||||
|
|
@ -41,9 +47,10 @@ public class MailPlugin extends org.imixs.marty.profile.MailPlugin {
|
||||||
/*
|
/*
|
||||||
* Now Set Sender, From and ReplyTo addresses...
|
* Now Set Sender, From and ReplyTo addresses...
|
||||||
*/
|
*/
|
||||||
logger.info("├── 📭 AGL: New mail message...");
|
|
||||||
// compute From address - can be overwritten by env mail.defaultSender
|
// compute From address - can be overwritten by env mail.defaultSender
|
||||||
InternetAddress adr = getInternetAddress(getFrom(documentContext, documentActivity));
|
InternetAddress adr = getInternetAddress(getFrom(documentContext,
|
||||||
|
documentActivity));
|
||||||
if (adr == null) {
|
if (adr == null) {
|
||||||
// in case of null we set an empty address here. This can happen in case
|
// in case of null we set an empty address here. This can happen in case
|
||||||
// of a RunAs Service EJB where the user context can not be resolved to a valid
|
// of a RunAs Service EJB where the user context can not be resolved to a valid
|
||||||
|
|
@ -54,30 +61,63 @@ public class MailPlugin extends org.imixs.marty.profile.MailPlugin {
|
||||||
// we will force a MessagingException...
|
// we will force a MessagingException...
|
||||||
adr = new InternetAddress("");
|
adr = new InternetAddress("");
|
||||||
} else {
|
} else {
|
||||||
// Test if a mailAuthenticatedSender.isPresent())
|
|
||||||
if (mailAuthenticatedSender.isPresent()) {
|
if (mailAuthenticatedSender.isPresent()) {
|
||||||
logger.info("│ ├── set authenticatedSender");
|
logger.info("├── 📭 set authenticated sender...");
|
||||||
logger.info("│ ├── set sender='" + mailAuthenticatedSender.get() + "'");
|
String mailDefaultPattern = mailAuthenticatedSender.get();
|
||||||
mailMessage.setHeader("Sender", mailAuthenticatedSender.get());
|
String sender = mailDefaultPattern;
|
||||||
}
|
// Expected format "COMPANY - {username} <webmaster@info.com>"
|
||||||
// default - current sender
|
int start = mailDefaultPattern.lastIndexOf('<');
|
||||||
mailMessage.setFrom(adr);
|
int end = mailDefaultPattern.lastIndexOf('>');
|
||||||
logger.info("│ ├── from:" + adr.getAddress());
|
if (start >= 0 && end >= 0) {
|
||||||
|
String senderDisplayName = mailDefaultPattern.substring(0, start);
|
||||||
|
sender = mailDefaultPattern.substring(start + 1, end);
|
||||||
|
logger.info("│ ├── sender='" + sender + "'");
|
||||||
|
mailMessage.setHeader("Sender", sender);
|
||||||
|
|
||||||
// Dow we have a replay to?
|
// create custom from...
|
||||||
String sReplyTo = getReplyTo(documentContext, documentActivity);
|
String userName = this.getWorkflowService().getUserName();
|
||||||
if ((sReplyTo == null) || (sReplyTo.isEmpty())) {
|
String userDisplayName = userName;
|
||||||
sReplyTo = adr.getAddress();
|
String userEmail = userName;
|
||||||
}
|
ItemCollection profile = profileService.findProfileById(userName);
|
||||||
logger.info("│ ├── replyTo:" + sReplyTo);
|
if (profile != null) {
|
||||||
InternetAddress[] resplysAdrs = new InternetAddress[1];
|
userDisplayName = profile.getItemValueString("txtuserName");
|
||||||
resplysAdrs[0] = getInternetAddress(sReplyTo);
|
userEmail = profile.getItemValueString("txtemail");
|
||||||
mailMessage.setReplyTo(resplysAdrs);
|
senderDisplayName = senderDisplayName.replace("{username}", userDisplayName);
|
||||||
|
} else {
|
||||||
|
logger.warning(
|
||||||
|
"├── ⚠️ no matching user profile found for " + userName);
|
||||||
|
}
|
||||||
|
InternetAddress fromAddress = new InternetAddress(sender, senderDisplayName);
|
||||||
|
mailMessage.setFrom(fromAddress);
|
||||||
|
logger.info(
|
||||||
|
"│ ├── from:" + fromAddress.getPersonal() + "<" + fromAddress.getAddress() + ">");
|
||||||
|
logger.info("│ ├── replyTo:" + userEmail);
|
||||||
|
InternetAddress[] replyToAddressList = new InternetAddress[1];
|
||||||
|
replyToAddressList[0] = getInternetAddress(userEmail);
|
||||||
|
mailMessage.setReplyTo(replyToAddressList);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// default behavior - set sender and reply only
|
||||||
|
logger.info("│ ├── sender='" + sender + "'");
|
||||||
|
mailMessage.setHeader("Sender", sender);
|
||||||
|
// Dow we have a replay to?
|
||||||
|
String sReplyTo = getReplyTo(documentContext, documentActivity);
|
||||||
|
if ((sReplyTo == null) || (sReplyTo.isEmpty())) {
|
||||||
|
sReplyTo = adr.getAddress();
|
||||||
|
}
|
||||||
|
logger.info("│ ├── replyTo:" + sReplyTo);
|
||||||
|
InternetAddress[] resplysAdrs = new InternetAddress[1];
|
||||||
|
resplysAdrs[0] = getInternetAddress(sReplyTo);
|
||||||
|
mailMessage.setReplyTo(resplysAdrs);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (MessagingException e) {
|
} catch (MessagingException | UnsupportedEncodingException e) {
|
||||||
throw new PluginException(MailPlugin.class.getSimpleName(), ERROR_MAIL_MESSAGE, e.getMessage(), e);
|
throw new PluginException(MailPlugin.class.getSimpleName(),
|
||||||
|
ERROR_MAIL_MESSAGE, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -1485,6 +1485,7 @@ result.isValid=true;
|
||||||
</imixs:item>
|
</imixs:item>
|
||||||
<imixs:item name="nammailreceiver" type="xs:string">
|
<imixs:item name="nammailreceiver" type="xs:string">
|
||||||
<imixs:value><![CDATA[ralph.soika@imixs.com]]></imixs:value>
|
<imixs:value><![CDATA[ralph.soika@imixs.com]]></imixs:value>
|
||||||
|
<imixs:value><![CDATA[test-ntxn36ljd@srv1.mail-tester.com]]></imixs:value>
|
||||||
</imixs:item>
|
</imixs:item>
|
||||||
<imixs:item name="nammailreceivercc" type="xs:string">
|
<imixs:item name="nammailreceivercc" type="xs:string">
|
||||||
<imixs:value/>
|
<imixs:value/>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue