我想使用Linux外部命令“mail”从scala发送电子邮件。 命令执行有效,只是我在设置主题字符串时遇到麻烦,这里有一些尝试:
SENT OK
scala> val email="me@email.it"
email: String = me@email.it
scala> val result = "echo ECCO" #| s"mail -s ciao_bello $email " !
warning: there was one feature warning; re-run with -feature for details
result: Int = 0
SENT但主题:ciao
scala> val subject="ciao bello !"
subject: String = ciao bello !
scala> val result = "echo BODY" #| s"mail -s $subject $email " !
warning: there was one feature warning; re-run with -feature for details
rewrite: excessive recursion (max 50), ruleset Canonify2
result: Int = 0
SENT但主题:“ciao”
scala> val subject= "\"ciao bello !\""
subject: String = "ciao bello !"
scala> val result = "echo BODY" #| s"mail -s $subject $email " !
warning: there was one feature warning; re-run with -feature for details
!"... Unbalanced '"'
result: Int = 0
不是
scala> val result = "echo BODY" #| s"mail -s \"ciao bello\" $email " !
<console>:10: error: value ciao is not a member of `enter code here`scala.sys.process.ProcessBuilder
val result = "echo BODY" #| s"mail -s \"ciao bello\" $email " !
<console>:10: error: not found: value bello
val result = "echo BODY" #| s"mail -s \"ciao bello\" $email " !
我如何处理包含多个单词的主题?
答案 0 :(得分:1)
有些失败者给了我解决方案,但只是在正确发送电子邮件之前进行了调整:
scala> val subject="\"ciao bello !\""
subject: String = "ciao bello !"
scala> val result = Seq("sh", "-c", s"echo BODY | mail -s $subject $email") !
warning: there was one feature warning; re-run with -feature for details
result: Int = 0
谢谢,欢呼!