<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do you send an e-mail as the System user? in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/how-do-you-send-an-e-mail-as-the-system-user/m-p/249634#M202764</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, I'm trying to write a script to execute antivirus check (as per &lt;/SPAN&gt;&lt;A href="http://wiki.alfresco.com/wiki/Antivirus" rel="nofollow noopener noreferrer"&gt;http://wiki.alfresco.com/wiki/Antivirus&lt;/A&gt;&lt;SPAN&gt;) and send an e-mail if there is a virus detected.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;NodeRef fromPerson = null;&lt;BR /&gt;if (! authService.isCurrentUserTheSystemUser())&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fromPerson = personService.getPerson(authService.getCurrentUserName());&lt;BR /&gt;}&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried everything I can think of, including using &lt;/SPAN&gt;&lt;EM&gt;AuthenticationUtil.runAs&lt;/EM&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;@Override&lt;BR /&gt;protected void executeImpl(final Action ruleAction, final NodeRef actionedUponNodeRef) {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;boolean result1 = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork&amp;lt;Boolean&amp;gt;() {&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;And I've also tried wrapping the transaction, as I saw through some of the Alfresco source code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;@Override&lt;BR /&gt;public Boolean doWork() throws Exception {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback&amp;lt;Boolean&amp;gt;() {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public Boolean execute() throws Throwable {&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;But in both cases, the code is &lt;/SPAN&gt;&lt;STRONG&gt;never&lt;/STRONG&gt;&lt;SPAN&gt; run as the system user. I think I recall somewhere saying that &lt;/SPAN&gt;&lt;EM&gt;getCurrentUser()&lt;/EM&gt;&lt;SPAN&gt; 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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Nov 2012 05:17:07 GMT</pubDate>
    <dc:creator>jevon</dc:creator>
    <dc:date>2012-11-14T05:17:07Z</dc:date>
    <item>
      <title>How do you send an e-mail as the System user?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/how-do-you-send-an-e-mail-as-the-system-user/m-p/249634#M202764</link>
      <description>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 t</description>
      <pubDate>Wed, 14 Nov 2012 05:17:07 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/how-do-you-send-an-e-mail-as-the-system-user/m-p/249634#M202764</guid>
      <dc:creator>jevon</dc:creator>
      <dc:date>2012-11-14T05:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do you send an e-mail as the System user?</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/how-do-you-send-an-e-mail-as-the-system-user/m-p/249635#M202765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It might just be easier to use a different e-mail address that accepts email forgery, and then forward those emails as necessary…&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Apr 2013 03:58:03 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/how-do-you-send-an-e-mail-as-the-system-user/m-p/249635#M202765</guid>
      <dc:creator>jevon</dc:creator>
      <dc:date>2013-04-12T03:58:03Z</dc:date>
    </item>
  </channel>
</rss>

