问题
I am trying to write a groovy files that parse some data and send email.
I tried to import below packages for this purpose:
import javax.mail.*
import javax.mail.internet.*
And tried to run the groovy file as ./test.groovy
, but it shows the error "import command not found"
Is this the correct way to run the groovy script? Anyone please help me to write a groovy script that helps to email
回答1:
The javax.mail
classes are not part of the JDK, so you need to explicitly include them. In a Groovy script, the easiest way to do this is with @Grab
, e.g.
@Grab(group='javax.mail', module='mail', version='1.4.7')
import javax.mail.*
import javax.mail.internet.*
// the rest of your script goes here
回答2:
You can send an email by using the Email-ext plugin as follows:
emailext body: '''African child
African child''', subject: 'African child', to: 'patrick@xxxx'
Note that this will only work within a proper job, not in Jenkins script interface
来源:https://stackoverflow.com/questions/38645361/run-groovy-script-sending-email