无法使用Ruby发送带有Mailgun的链接URL
我使用的是Mailgun的curl命令的格式,它允许我发送消息的HTML版本以及明文备份,并在Ruby脚本中运行它。问题是,当我试图在消息的HTML部分中包含链接时,总是会出现语法错误 我意识到这是一个逃避特殊角色的问题,但我还没能把它解决掉 以下是主文件:无法使用Ruby发送带有Mailgun的链接URL,ruby,mailgun,Ruby,Mailgun,我使用的是Mailgun的curl命令的格式,它允许我发送消息的HTML版本以及明文备份,并在Ruby脚本中运行它。问题是,当我试图在消息的HTML部分中包含链接时,总是会出现语法错误 我意识到这是一个逃避特殊角色的问题,但我还没能把它解决掉 以下是主文件: require './message_template.rb' require './html_template.rb' fromLabel = "***** *******" fromAddress = "****@mail.*****
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>."
将转义字符放入字符串后
$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}'"
该更改导致以下更改的错误代码:“sh:-c:第0行:查找匹配项时出现意外的EOF`sh:-c:第1行:语法错误:意外的文件结尾”