问题
hi I have a simple pipeline job that should send a mail, I configured on Manage jenkins -> Configure System with port 465 and the appropriated SMTP server , when I test the configuration by sending a e-mail , it sends and I can see the test mail on my inbox , but from the pipeline job , it fails:
node {
stage("test") {
def message = "hello there!"
mail bcc: '', body: message, cc: '', from: 'jenkinsuser@mycom.com', replyTo: 'jenkinsuser@mycom.com', subject: "Develop: build generated ", to:'grace@mycom.com'
}
}
Error:
java.net.SocketException: Connection closed by remote host
at sun.security.ssl.SSLSocketImpl.checkWrite(Unknown Source)
at sun.security.ssl.AppOutputStream.write(Unknown Source)
at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java:114)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.flush(Unknown Source)
at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2104)
Caused: javax.mail.MessagingException: Can't send command to SMTP host;
nested exception is:
java.net.SocketException: Connection closed by remote host
at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2106)
at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2093)
at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1184)
Any suggestion how to fix it?
thanks,
回答1:
I am using Email Extension plugin in scripted pipeline with no issues. Make sure you properly configured E-mail Notification section in Manage Jenkins > Configure System. Example for gmail: Jenkins e-mail notifications settings
Plugin usage is described here: here. This is how I call it in Pipeline (I didn't remove variables):
emailext attachmentsPattern: "**/packages/rpm/splitted/${file}",
to: "${to}",
from: "Jenkins",
subject: "[jenkins] ${packageFullName}: part ${part}/${files.size()}",
body: "File received: \'${file}\'\n" +
"From package: \'${packageFullName}\'\n" +
"Package MD5: \'${mainMdFiveSum}\'\n" +
"Jenkins Build: \'${env.BUILD_URL}\'\n"
来源:https://stackoverflow.com/questions/58033585/sending-a-mail-on-jenkins-pipeline