2017-04-14 30 views
0

我正在使用Mailgun的curl命令的格式,它允许我发送消息的HTML版本以及明文备份并从Ruby脚本中运行它。问题是,当我尝试在消息的HTML部分中包含链接时,我总是收到语法错误。无法使用Ruby发送带Mailgun的链接URL

我意识到这是一个逃避特殊问题的问题,但我一直无法将它解决。

这里是主文件:

require './message_template.rb' 
require './html_template.rb' 

fromLabel = "***** *******" 
fromAddress = "****@mail.*******.com" 
toAddress = "[email protected]*******.net" 
subject = "Hello" 

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 + "'" + " '+ --form-string html=' " + $htmlMessage + "'" 

system (cmd) 

这是第一个帮助文件:

#message_template.rb 
$message = "Hello, this is a plaintext message." 

而第二个辅助文件:

#html_template.rb 
$htmlMessage = "Hello, this is a HTML message with <a href="https://www.stackoverflow.com">link</a>." 

回答

1

一旦你把转义字符到字符串

$htmlMessage = "Hello, this is a HTML message with <a href=\"https://www.stackoverflow.com\">link</a>." 

试试这个:

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}' --form-string html='#{$htmlMessage}'" 
+0

是改变了以下结果,改变错误代码: 'SH:-c:0行:意外的EOF而寻找匹配''” SH:-c:第1行:语法错误:文件意外结束' – HMLDude

+0

@pweslow请参阅编辑 – Ruslan