无法使用 Mailgun 使用 Ruby 发送 Link URL
Unable To Send Link URL with Mailgun using Ruby
我正在使用 Mailgun 的 curl 命令的格式,它允许我发送消息的 HTML 版本以及纯文本备份和 运行 它来自 [=29] =] 脚本。问题是,当我尝试在消息的 HTML 部分中包含 link 时,我不断收到语法错误。
我知道这是一个转义特殊字符问题,但我一直没能解决它。
这是主要文件:
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.whosebug.com">link</a>."
将转义字符放入字符串后
$htmlMessage = "Hello, this is a HTML message with <a href=\"https://www.whosebug.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}'"
我正在使用 Mailgun 的 curl 命令的格式,它允许我发送消息的 HTML 版本以及纯文本备份和 运行 它来自 [=29] =] 脚本。问题是,当我尝试在消息的 HTML 部分中包含 link 时,我不断收到语法错误。
我知道这是一个转义特殊字符问题,但我一直没能解决它。
这是主要文件:
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.whosebug.com">link</a>."
将转义字符放入字符串后
$htmlMessage = "Hello, this is a HTML message with <a href=\"https://www.whosebug.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}'"