Run Groovy script - Sending email

╄→尐↘猪︶ㄣ 提交于 2019-12-12 03:38:59

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!