HMLDude
HMLDude

Reputation: 1637

Unable To Send Link URL with Mailgun using Ruby

I am using the format of Mailgun's curl command, which allows me to send both an HTML version of the message as well as a plaintext backup and running it from inside a Ruby script. The problem is that I keep getting a syntax error when I try to include a link in the HTML portion of the message.

I realize that this is an escape special character issue, but I haven't been able to get it straitened out.

Here is the main file:

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)

Here is the first helper file:

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

And the second helper file:

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

Upvotes: 0

Views: 155

Answers (1)

Ruslan
Ruslan

Reputation: 2009

Once you put escape characters into the string

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

Give this a try:

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}'"

Upvotes: 1

Related Questions