'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.
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:
- Log in as administrator on Jenkins
- Click on "Manage Jenkins"
- Click on "Configure System"
- Locate both SMTP server - and set to your AWS zone email server
- Click on 'Advanced' below BOTH
- Make sure "Use TLS" is checked on both
- Make sure the SMTP port is set to 587 for both
- 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
- 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!).
- Locate "Default Pre-send Script" section
- 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]"))
- 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.
- 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 |

