运行Groovy脚本-发送电子邮件 [英] Run Groovy script - Sending email
问题描述
我试图编写一个可解析某些数据并发送电子邮件的常规文件。
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.*
并尝试以 ./ test.groovy
的形式运行groovy文件,但显示错误 import command找不到
And tried to run the groovy file as ./test.groovy
, but it shows the error "import command not found"
这是运行groovy脚本的正确方法吗?任何人都可以帮助我编写一个有助于发送电子邮件的groovy脚本
Is this the correct way to run the groovy script? Anyone please help me to write a groovy script that helps to email
推荐答案
javax.mail
类不是JDK的一部分,因此您需要显式包括它们。在Groovy脚本中,最简单的方法是使用 @Grab
,例如
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
这篇关于运行Groovy脚本-发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!