rubyemailsparkpost

How to set reply_to/reply-to using SparkPosts Ruby API client?


It seems like I can't set reply_to in vals hash when I'm using SparkPost::Client.new().send_message(param1,param2,etc...). Egs here: https://github.com/SparkPost/ruby-sparkpost

Meaning, when I send an email through the client - I want the end-user (that receives the email) to automatically have the reply_to attr (NOT the from attr) fill out the Reply To: field for a given ESP.

I've also seen this: https://github.com/SparkPost/ruby-sparkpost/blob/master/examples/transmission/with_template.rb. Which uses send_payload.

Does anyone know how to set the reply_toso it doesn't simply default to the from's email address?


Solution

  • Figured it out. Currently, you must use the SparkPost::Client.new().transmission.send_payload method and build the payload yourself.

    Example:

    payload = {
      recipients: [{tags:[tag1,tag2],address:{email:foo@bar.com}}],
      content: {
        from: "Someone <no-reply@somewhere.io>",
        subject: "Your awesome subject",
        reply_to: "Someone Else <totally.hit.me.up@somewhere.else.io>",
        html:"<h1>Hello World</h1>"
      }
    }
    SparkPost::Client.new().transmission.send_payload(payload)