i need to send a mail notification using jenkins (if it is a success build or someting went wrong)
Right now i have something like that:
pipeline {
agent any
...Some stages ...
post {
success {
mail to:"[email protected]", subject:"SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay, we passed."
}
failure {
mail to:"[email protected]", subject:"FAILURE: ${currentBuild.fullDisplayName}", body: "Boo, we failed."
}
}
}
But when i execute i get the following error:
java.net.ConnectException: Connection refused: connect
Caused: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
I guess i cannot send on the port 25 i need to send it on the port 465.. am i wrong?But i dont know how can i do this.
In most of the examples they use plugins to the jenkins, but i can only use code (declarative pipeline)
suggestions?
Basically, declarative and scripted pipelines differ in terms of the programmatic approach. One uses a declarative programming model and the second uses an imperative programming mode. Declarative pipelines break down stages into multiple steps, while in scripted pipelines there is no need for this.
A declarative pipeline supports conditional statement usage, allows access to environment variables and provides facilities to add logging and error handling. The tradeoff is that declarative pipelines don't allow deep integration into Groovy and Java APIs.
To send email, the plugin needs the smtp configured. Go to Manage Jenkins > Configure System > search for “Extended E-mail Notification”. Configure the smtp. Example: My configuration with gmail smtp.
Jenkins default email server attempts to run through your localhost on port 25. That error message indicates, as you have guessed, that you need to change the email settings.
To do so, go to Manage Jenkins -> Configure System -> Email Notifcation or Extended Email Notification
As an aside, unless you have an email server running locally (and I'd be surprised if that was the case), changing the local port number won't work. You would need to point it to an external server. Here is a setting page for having Jenkins use the Google SMTP server, for instance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With