ant发送邮件功能,需要在ant的安装目录/lib目录下,添加jar包 mail.jar 和 activation.jar。
编写xml
<?xml version="1.0" ?><PRoject name="mailReport" default="sendMail" > <target name="sendMail" > <mail mailhost="smtp.QQ.com" mailport="465" subject="send mail test" user="8888888" passWord="*******" messageMimeType="text/html" > <from address="8888888" /> <to address="6666666" /> <!-- 邮件内容 --> <message><![CDATA[ <p>send test mail</p> <p>cha kan fangshi</p> ]]></message> <!-- 附件 --> <attachments> <fileset dir="." > <include name="test.tar.gz" /> </fileset> </attachments> </mail> </target></project>mailhost:发件服务器地址;mailport:发件端口;subject:邮件主题;cc:抄送
执行后,总是报错:
Buildfile: 。。。。。。/mail.xmlsendMail: [mail] Sending email:send mail test [mail] Failed to send email: 500 Error: bad syntaxBUILD FAILED
是在linux上执行的,最后发现是hosts的问题。
执行hostname -i,如果没有出现hostname或者ip,说明/etc/hosts里面没有给127.0.0.1对应地址。
解决方法:编辑/etc/hosts,添加 127.0.0.1 ${hostname} (注:中间有空格,hostname的位置写你的设备的hostname或者IP地址都可以)
新闻热点
疑难解答