无法使用Ruby

时间:2017-04-11 20:29:19

标签: ruby mailgun

我使用两个文件用Mailgun发送消息。他们是:

email_sender.rb
message_text.rb

第一个的代码是:

require './message_text.rb'

fromLabel = "Email Guy"
fromAddress = "digital@mail.*****.com"
toAddress = "info@*****.net"
subject = "An Invitation"

cmd = "curl -s --user 'api:key-*****' https://api.mailgun.net/v3/mail.*****.com/messages -F from='" + fromLabel + " <" + fromAddress + ">' -F to='" +toAddress + "' -F subject='" + subject + "' -F text='" + $message + "'"

wasGood = system (cmd)

第二个文件的代码是:

$message = "Line One Text."
+ "\n" + "\n" + "And Line Two Text!"

当我测试发送电子邮件时,到达我的测试帐户收件箱的邮件如下。

Line One Text.

2 个答案:

答案 0 :(得分:2)

如果您使用ruby -w运行代码,即:启用警告后,它会发出警告:warning: possibly useless use of + in void context,并带有相应的行号,指向:

$message = "Line One Text."
+ "\n" + "\n" + "And Line Two Text!" 

这是Ruby的一种礼貌方式:&#34;嗯,它不是语法错误,但对我来说没有意义。&#34; 尝试使用

$message = "Line One Text.

And Line Two Text!" # or: "Line One Text.\n\nAnd Line Two Text!" 

答案 1 :(得分:0)

所以我把它放在一条线上就可以了。

$message = "Line One Text!" + "\n" + "\n" + "Line Two Text!"