title: Jenkins email-ext plugin - Use scriptler to set msg sender email address
body: <p>I have a groovy script under $JENKINS_HOME/email-templates named sender_email_address.groovy which has the following code</p>
  
  <pre><code>&lt;%
  StringBuilder builderEmail = new StringBuilder()
  builderEmail.append("${build.buildVariables.get('BUILD_USER')}")
  builderEmail.append("@collective.com")
  def sender_email = builderEmail.toString()
  %&gt;
  ${sender_email}
  </code></pre>
  
  <p>I am trying to set the email sender address from the pre-send script of email-ext plugin. Here is the code which does that:</p>
  
  <pre><code>import javax.mail.Message.RecipientType
  import javax.mail.Address
  import javax.mail.internet.InternetAddress
  import javax.mail.internet.MimeMessage
  
  def senderAddress = ${SCRIPT, script="sender_email_address.groovy"}
  listener.logger("Sender address = " + senderAddress)
  msg.setFrom(new InternetAddress(senderAddress))
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>def senderAddress = Error in script or template: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
  Script1.groovy: 1: unexpected token: &lt; @ line 1, column 1.
  &lt;%
  ^
  </code></pre>
  
  <p>I am trying to set the from address of the email being sent to be the user who is logged in. I have the access to ${BUILD_USER} value available. But if I directly use it in the pre-send script as shown below</p>
  
  <pre><code>msg.setFrom(new InternetAddress("${BUILD_USER}")
  </code></pre>
  
  <p>the script directly replaces the ${BUILD_USER} token with the email address in the script itself. This defeats the purpose of tokenizing it since the next time I log in with a different user, the token isn't available to be replaced. Is there a way I can achieve it elsewhere just retaining the token ${BUILD_USER}?</p>