2017-04-11 54 views
0

我正在使用兩個文件通過Mailgun發送消息。它們是:無法使用紅寶石發送帶有Mailgun的多行純文本電子郵件

email_sender.rb 
message_text.rb 

的第一個代碼是:

require './message_text.rb' 

fromLabel = "Email Guy" 
fromAddress = "[email protected]*****.com" 
toAddress = "[email protected]*****.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

如果您用ruby -w的代碼,那就是:如果打開了警告,它警告說:warning: possibly useless use of + in void context,與根據行號,指向:

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

這是紅寶石的一種禮貌的方式說:「好吧,這不是一個語法錯誤,但它對我沒有意義。」 試一下

$message = "Line One Text. 

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

因此,我通過把所有東西放在一條線上來工作。

$message = "Line One Text!" + "\n" + "\n" + "Line Two Text!" 
相關問題