Neue Mail Funktion (sende option)

This commit is contained in:
Ralph Soika 2025-06-07 10:13:20 +02:00
parent 216589537c
commit 830394c7a3
4 changed files with 2093 additions and 2 deletions

View file

@ -6,7 +6,7 @@
<parent> <parent>
<artifactId>office-alexander-logistics</artifactId> <artifactId>office-alexander-logistics</artifactId>
<groupId>com.alexander-logistics</groupId> <groupId>com.alexander-logistics</groupId>
<version>1.3.2</version> <version>1.3.3</version>
</parent> </parent>
<artifactId>office-alexander-logistics-app</artifactId> <artifactId>office-alexander-logistics-app</artifactId>
<packaging>war</packaging> <packaging>war</packaging>

View file

@ -0,0 +1,86 @@
package com.alexanderlogistics.mail;
import java.util.Optional;
import java.util.logging.Logger;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.exceptions.PluginException;
import jakarta.inject.Inject;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeMessage;
/**
* Dieses Plugin überschreibt einfach nur From und Sender im Header. Ist in
* neuen Versionen von Imixs-Workflow 6.2.2 automatisch gelöst.
*
*/
public class MailPlugin extends org.imixs.marty.profile.MailPlugin {
private static final Logger logger = Logger.getLogger(MailPlugin.class.getName());
@Inject
@ConfigProperty(name = "mail.authenticatedSender")
Optional<String> mailAuthenticatedSender;
/**
* This method adds the attachments of the blob workitem to the MimeMessage
*/
@Override
public ItemCollection run(ItemCollection documentContext, ItemCollection documentActivity) throws PluginException {
// run default functionality
ItemCollection result = super.run(documentContext, documentActivity);
boolean debug = true; // immer debuggen!!
// now get the Mail Session object and adapt sender and from!!
MimeMessage mailMessage = (MimeMessage) super.getMailMessage();
if (mailMessage != null) {
try {
/*
* Now Set Sender, From and ReplyTo addresses...
*/
logger.info("├── 📭 AGL: New mail message...");
// compute From address - can be overwritten by env mail.defaultSender
InternetAddress adr = getInternetAddress(getFrom(documentContext, documentActivity));
if (adr == null) {
// 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
// smtp address
if (debug) {
logger.warning("│   ├── from address was resolved to null");
}
// we will force a MessagingException...
adr = new InternetAddress("");
} else {
// Test if a mailAuthenticatedSender.isPresent())
if (mailAuthenticatedSender.isPresent()) {
logger.info("│   ├── set authenticatedSender");
logger.info("│   ├── set sender='" + mailAuthenticatedSender.get() + "'");
mailMessage.setHeader("Sender", mailAuthenticatedSender.get());
}
// default - current sender
mailMessage.setFrom(adr);
logger.info("│   ├── from:" + adr.getAddress());
// 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) {
throw new PluginException(MailPlugin.class.getSimpleName(), ERROR_MAIL_MESSAGE, e.getMessage(), e);
}
}
return result;
}
}

View file

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.alexander-logistics</groupId> <groupId>com.alexander-logistics</groupId>
<artifactId>office-alexander-logistics</artifactId> <artifactId>office-alexander-logistics</artifactId>
<version>1.3.2</version> <version>1.3.3</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Imixs Office Workflow - Custom Build</name> <name>Imixs Office Workflow - Custom Build</name>

2005
workflow/debug-de-1.0.0.bpmn Normal file

File diff suppressed because it is too large Load diff