'How to set from address in Jenkins with email-ext plugin?

Using AWS SES as mail server. Set smtp, username and password at Extended E-mail Notification area. But didn't find where to set from address. If don't set it, the send mail will be failure:

SendFailedException message: 501 Invalid MAIL FROM address provided

At Jenkins Location area, there is a System Admin e-mail address input. Even set an address there, can't send mail successfully.

enter image description here



Solution 1:[1]

The following was tested with Jenkins 2.319.3:

So, with the extended email plugin - it does NOT properly distinguish between the FROM email address - from the SMTP user name, unlike the built-in email. Because AWS SES requires the FROM address to be a validated email - they need to be different from each other. If you are not using pipeline - you can set the FROM address by:

  1. Log in as administrator on Jenkins
  2. Click on "Manage Jenkins"
  3. Click on "Configure System"
  4. Locate both SMTP server - and set to your AWS zone email server
  5. Click on 'Advanced' below BOTH
  6. Make sure "Use TLS" is checked on both
  7. Make sure the SMTP port is set to 587 for both
  8. In the "E-mail Notification" - turn on the "Use SMTP Authentication" and use the specific AWS generated SMTP username and password (not the FROM address!) for the "User Name" and "Password" in that section
  9. In the "Extended E-mail Notification" - (in the expanded "Advanced" section) - set the "SMTP Username" and "SMTP Password" to use the specific AWS generated SMTP username and password (not the FROM address!).
  10. Locate "Default Pre-send Script" section
  11. Add the following (changing the [email protected] to your FROM email to use)
import javax.mail.Message.RecipientType
import javax.mail.Address
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeMessage
msg.setFrom(new InternetAddress("[email protected]"))  
  1. Verify that the default presend script in ALL of your extended email tasks use $DEFAULT_PRESEND_SCRIPT - otherwise you have to pre-append/edit your local script to include the above.
  2. Test! (Always a good thing to create a test job to validate - I created jobs that forced failures - with an extended email notification - to check that I got the emails with the attachments via SES.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Legobotics