cancel
Showing results for 
Search instead for 
Did you mean: 

How to change the 'From' address in a workflow notification?

ksar
Champ in-the-making
Champ in-the-making
Hello, everyone.

What currently happens:
- a user creates a new workflow. Alfresco sends a notification to everyone who needs to be notified. The e-mail address of the workflow creator is used as the sender.

What I need to happen:
- a user creates a new workflow. Alfresco sends a notification to everyone who needs to be notified. A default e-mail address is used as the sender, and it is the same for any created workflows.

Is there any way to achieve this?

The reason why I need this: security rules that block mails not from the default e-mail address. I have been informed that these rules will not be changed.
10 REPLIES 10

mrogers
Star Contributor
Star Contributor
You will need to change the Mail Action Executor class.  Or replace it with your own version.

This is a known issue.

ksar
Champ in-the-making
Champ in-the-making
You will need to change the Mail Action Executor class.  Or replace it with your own version.

This is a known issue.

Thank you. Is this something that can be changed in an existing installation of Alfresco? If so, which file(s) would I have to change?

mrogers
Star Contributor
Star Contributor
Override "mail" bean.   With your own MailActionExecuter.

ksar
Champ in-the-making
Champ in-the-making
Thanks.

ksar
Champ in-the-making
Champ in-the-making
All right, so over the past few days, I have tried to figure out how to do this. Unsuccessfully.

I downloaded the Alfresco SDK, used it to make my own custom MailActionExecutorOverride class, dropped the .jar into the Alfresco installation's lib folders (all of them, since I couldn't figure out which one was the right one) and then specified it to be used in the mail bean (outboundSMTP-context.xml) instead of the original MailActionExecutor. After some debugging, Alfresco started without Exceptions produced by my custom class showing up in the log.

However, Alfresco is still using the original org.alfresco.repo.action.executer.MailActionExecuter, as I could see in an Exception log. It is also still using the users' e-mail addresses.  

I have no idea how to actually override the existing org.alfresco.repo.action.executer.MailActionExecuter class, if that is indeed what I have to do.
Before being assigned to this task, I had no prior knowledge of Tomcat, Alfresco, or Spring, so I am currently completely lost.

ksar
Champ in-the-making
Champ in-the-making
All right, I appear to have managed to change this now. It's probably not a good solution, but at least it now does what I need it to. Here is what I did, in case someone else has a similar problem:

  • Downloaded the Alfresco source code

  • Found the source code for the MailActionExecutor class

  • Made a new project and copied the MailActionExecutor.java file into it.

  • Set references to all the .jar files used by the MailActionExecutor.java class

  • Edited the source code so that all "from" email addresses now use a (hardcoded) default address

  • Exported the edited MailActionExecutor as a .jar file

  • Decompressed my .jar and found the five .class files that were generated

  • Used those five files to replace the ones in \tomcat\webapps\alfresco\WEB-INF\lib\alfresco-repository-4.0.c jar (using 7zip)

  • Made alfresco-repository-4.0.c read-only to prevent it being overwritten when/if alfresco explodes stuff
Results:
  • from addresses in workflow notifications are now the default address, regardless of who creates the workflow

  • from addresses in all other e-mails are also the default address, which is an acceptable loss
So, did I neglect anything important that is going to make this solution blow up in my face?

chrisokelly
Champ on-the-rise
Champ on-the-rise
I attempted to followed Ksar's steps (dubiously, as I haven't touched real java, only js up till now) and came up with this -
// set the from address
                String fromActualUser = null;
                if (fromPerson != null)
                {
                    fromActualUser = (String) nodeService.getProperty(fromPerson, ContentModel.PROP_EMAIL);
                }
                String from = (String)ruleAction.getParameterValue(PARAM_FROM);
                if (from == null || from.length() == 0)
                {
                  if (fromActualUser != null && fromActualUser.length() != 0)
                    {
                        message.setFrom(fromActualUser);
                    }
                    else
                    {
                       message.setFrom(fromAddress);
                    }
                     else
                      {
                        message.setFrom(from);
                      }
                }

which, to me at least, seems like the logic this should have been following in the first place (although I am sure there is a reasoning behind the way it works that is beyond my own grok)

Essentially, the logic is as follows-
Is the action initiated by a user? 
   If so, get the users email address.
Was a from address not set manually by this script?
   If so, did we get a user above who had an email address?
      If so, use that address
      If not, use the default from address
   If not (ie there was a from address set manually) use that
   
Or, to put it differently-
Prefer to use a manually set from address from the script if it exists (why would it be set manually if not to be used?)
If that is lacking, try to get the initiating users email address and use that
if it wasn't a normal user who initiated it, or it was and they have no email address, use the default (fallback)

But I am not sure how to get this into class files. I found the .java file in the 4.0.d sdk to edit, I copied it into a newly created java project in Eclipse, creating it as a new package file. I chose file>export and exported as a jar, but when I unloaded the jar it only made 2 .class files, and popped a bunch of errors (I had no idea what was meant by setting references to the .jar files used and I believe this is what the errors referenced). I infer it has something to do with the import statements at the beginning of the file, but do not know what I should change them to.

I next created another new project, copied the entire src folder from the SDK into it as and made my changes just to the MailActionExecutor.java file in it, but when I tried to export it the button was disabled, I felt I needed to select more than the src folder to be exported but that was all it gave me under my project and would not drill down any further.

Is anyone able to give any direction on how to get these code changes into alfresco? If not, does anyone know when the from.enabled parameter I have seen in JIRA will show up in community? It seems odd that for so many versions there has been a from parameter in the mail action which is essentially useless!

mrogers
Star Contributor
Star Contributor
I suggest you take the class from HEAD.   This  has been "fixed" for some time.

chrisokelly
Champ on-the-rise
Champ on-the-rise
Having seen capitalized HEAD in several forums, I get the feeling this is a silly question, but when you say get the class from HEAD, what is the process you're referring to?