我正在使用Mailgun的curl命令格式,它允许我发送消息的HTML版本以及明文备份并从Ruby脚本中运行它。问题是当我尝试在消息的HTML部分中包含一个链接时,我不断收到语法错误。
我意识到这是一个逃避特殊角色问题,但我无法让它变得困难。
这是主文件:
require './message_template.rb'
require './html_template.rb'
fromLabel = "***** *******"
fromAddress = "****@mail.*******.com"
toAddress = "info@*******.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>."
答案 0 :(得分: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}'"