Hi, I'm trying to write a script to execute antivirus check (as per http://wiki.alfresco.com/wiki/Antivirus) and send an e-mail if there is a virus detected.However I've found out that the code is run as the current user (e.g. testUser) when it is triggered as part of a folde rrule, and this means that the e-mail "From:" header is set to the users' e-mail address. Per MailActionExecuter:
NodeRef fromPerson = null;
if (! authService.isCurrentUserTheSystemUser())
{
fromPerson = personService.getPerson(authService.getCurrentUserName());
}
Certain mail servers (i.e. mine) are configured to drop e-mails if the From: address is from that server and the given server is not a designated sender. i.e. certain mail servers will simply not accept forged e-mails from unknown senders in order to reduce spam. I also have a dynamic IP so I can't simply add my IP as a designated sender. This means that I need to find some way to run the Java code as the System user.I've tried everything I can think of, including using AuthenticationUtil.runAs:
@Override
protected void executeImpl(final Action ruleAction, final NodeRef actionedUponNodeRef) {
boolean result1 = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Boolean>() {
And I've also tried wrapping the transaction, as I saw through some of the Alfresco source code:
@Override
public Boolean doWork() throws Exception {
return doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Boolean>() {
public Boolean execute() throws Throwable {
But in both cases, the code is never run as the system user. I think I recall somewhere saying that getCurrentUser() will always return the actual user rather than the runAs user - if this is true, I guess that I will never be able to send e-mails as the System user.Any ideas? Can I configure the script to run as another user? Can I modify the rule to run as another user in Share? (There are no "user" options in Share folder rule config.) Is there another way to send an e-mail that is actually from the System and not another user?