sendgrid-ruby icon indicating copy to clipboard operation
sendgrid-ruby copied to clipboard

Unable to make additions to `Content-Type` email headers (other than type)

Open coryjamescrook opened this issue 8 years ago • 14 comments

Issue Summary

Based on other issues posted, and a lot of digging, I have yet to accomplish adding other keys to the Content-Type email headers for sendgrid. Looking at https://github.com/sendgrid/sendgrid-ruby/blob/master/lib/sendgrid/helpers/mail/content.rb

It seems the support only extends to the type, ie. text/plain or text/calendar, etc...

But it would be great to supply other keys to this header, such as method=REQUEST or method=CANCEL - commonly used in event invites with icalendar.

Let me know if there's a way to set this I have missed, but I don't believe it's possible at the moment.

Steps to Reproduce

  1. Create an instance of mail
  2. mail.content allows for a type and a value, but no additional keys
  3. Trying to override with the custom_header of Content-Type returns an error, as that Header is reserved.

Technical details:

  • sendgrid-ruby Version: 5.2.0
  • ruby 2.4.2p198

coryjamescrook avatar Jun 28 '18 16:06 coryjamescrook

Hello @coryjamescrook,

Support for this was recently added for attachments. Perhaps that can fulfill your needs for .ics files. Please let me know.

With Best Regards,

Elmer

thinkingserious avatar Jul 03 '18 21:07 thinkingserious

Thanks for the response @thinkingserious. Unfortunately, the proposed solution doesn't seem to embed into an email (so you can accept, decline inline).

coryjamescrook avatar Jul 16 '18 21:07 coryjamescrook

Hi @coryjamescrook,

Do you mind sending us an example of what you are trying to achieve? Perhaps a screenshot and the source of the email? Thanks!

With Best Regards,

Elmer

thinkingserious avatar Jul 24 '18 00:07 thinkingserious

Hi @thinkingserious,

Thanks for your help with this. The journey has been quite frustrating!

What I need to happen is to send an iCalendar file via email when an appointment is booked. If an appointment is cancelled, that same appointment needs to be cancelled. I am able to accomplish this by creating an iCalendar file with the same id, incrementing the event version number.

From what I can gather from information available, not only does the iCalendar file need to specify all those specs, but the attachment needs to be of type text/calendar (hence my original request for setting content-type of attachments), and the metadata of content type for the email itself needs to be set to multipart/alternative. From what I can see in your docs, the content-type for the email is reserved, and probably dealt with on your end of the API.

The event being sent in this way should display the event as: screen shot 2018-07-25 at 11 23 18 am

This allows updates to be made to the event. But when the correct headers can't be set, mail clients default to creating a copy of the event, rendering updates (like cancellations) useless because the id of the event ultimately changes.

If you have any suggestions, it is greatly appreciated. I could be missing something in the docs. Cheers, Cory

coryjamescrook avatar Jul 25 '18 15:07 coryjamescrook

I had forgotten about this part as well, but it seems as if the Content-Transfer-Encoding gets set to quoted-printable, where all the invites I've been able to accept inline in the email contain the value of 7bit for the iCalendar file as one of the contents of the email, as well as base64 for the attachment containing the iCalendar file.

You might find this information useful in seeing if there's any way to set either of these header values through API.

Thanks again!

coryjamescrook avatar Jul 25 '18 17:07 coryjamescrook

Thanks for the excellent elaboration @coryjamescrook! I will share this with our product team to see what's possible on our end.

thinkingserious avatar Jul 25 '18 21:07 thinkingserious

Hi @coryjamescrook,

Do you mind sharing the relevant redacted code? I'd like to try and reproduce. Thanks!

With Best Regards,

Elmer

thinkingserious avatar Jul 26 '18 17:07 thinkingserious

@thinkingserious Any updates on this? I am trying to send iCalender by attachiing with emial. Works fine on google, but outlook mobile app (iOS/Android) required addition parameters on header.

It should be like Content-Type: text/calendar; charset=utf-8; method=REQUEST; " But Content-Type is reserved in Sendgrid.

I can achieve this using Nodemailer library, Client wants to use sendgrid. That's worst part.

Its been two years sendgrid working on this. How long it will take?

srjahir32 avatar Sep 29 '18 07:09 srjahir32

Hello @srjahir32,

Have you tried this?

With Best Regards,

Elmer

thinkingserious avatar Oct 02 '18 20:10 thinkingserious

@thinkingserious Yeah already tried this. It does not work. And its not solution to sending custom header. I had to choose nodemailer to make it work.

srjahir32 avatar Oct 03 '18 12:10 srjahir32

Any ideas @kylearoberts?

thinkingserious avatar Oct 05 '18 04:10 thinkingserious

Hey @srjahir32

We should be able to get calendar invites to work, but there are some things that cannot be done. One, you cannot set the charset/Content-Transfer-Encoding. The encoding of the text/calendar invite will always be quoted-printable, which should not be an issue from past testing. Now for how to send emails with calendar invites:

{
  "personalizations": [
    {
      "to": [
        {
          "email": "[email protected]",
          "name": "to_email name"
        }
      ]
    }
  ],
  "from": {
    "email": "[email protected]",
    "name": "from_email name"
  },
  "reply_to": {
    "email": "[email protected]",
    "name": "from_email name"
  },
  "subject":"Testing Calendar",
  "content": [
    {
      "type": "text/plain",
      "value": "Plain Content"
    },
    {
      "type": "text/html",
      "value": "HTML Content"
    },
    {
      "type": "text/calendar; method=REQUEST",
      "value": "Calendar Content"
    }
  ],
  "attachments": [
    {
      "content": "base64 attachment content",
      "type": "application/ics",
      "name": "invite.ics",
      "filename": "invite.ics",
      "disposition": "attachment"
    }
  ]
}

So in the example above you will notice that there is a place for an attachment and a text/calendar content. You will want both when sending your invite. Sending like this will result in an email that looks similar to this:

--fd9ba819db2985c7595e8067c78fb74d18c8c7bddf4258fdbc6de6b2af8f
Content-Type: multipart/alternative; boundary=ffdd7069baeff60a64e61082b3d4c25adc638a74cb107c9b5555113a9e94

--ffdd7069baeff60a64e61082b3d4c25adc638a74cb107c9b5555113a9e94
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
Mime-Version: 1.0

Plain Content

--ffdd7069baeff60a64e61082b3d4c25adc638a74cb107c9b5555113a9e94
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
Mime-Version: 1.0

HTML Content

--ffdd7069baeff60a64e61082b3d4c25adc638a74cb107c9b5555113a9e94
Content-Transfer-Encoding: quoted-printable
Content-Type: text/calendar; method=REQUEST; charset=UTF-8
Mime-Version: 1.0

Calendar content

--ffdd7069baeff60a64e61082b3d4c25adc638a74cb107c9b5555113a9e94--
--fd9ba819db2985c7595e8067c78fb74d18c8c7bddf4258fdbc6de6b2af8f
Content-Disposition: attachment; filename="something.ics"
Content-Transfer-Encoding: base64
Content-Type: application/ics; name="something.ics"

base64 content

--fd9ba819db2985c7595e8067c78fb74d18c8c7bddf4258fdbc6de6b2af8f--

So taking the kitchen sink example from here and modifying it a little, you get:

  mail = Mail.new
  mail.from = Email.new(email: '[email protected]')
  mail.subject = 'Testing Calendar'
  personalization = Personalization.new
  personalization.add_to(Email.new(email: '[email protected]', name: 'Example User'))
  mail.add_personalization(personalization)

  mail.add_content(Content.new(type: 'text/plain', value: 'some text here'))
  mail.add_content(Content.new(type: 'text/html', value: '<html><body>some text here</body></html>'))
  mail.add_content(Content.new(type: 'text/calendar; method=REQUEST', value: 'Calendar content'))

  attachment = Attachment.new
  attachment.content = 'base64 attachment content'
  attachment.type = 'application/ics'
  attachment.filename = 'invite.ics'
  attachment.disposition = 'attachment'
  mail.add_attachment(attachment)


  mail.reply_to = Email.new(email: '[email protected]')

I hope this clears things up. Please let me know if you have further questions.

Kyle

kylearoberts avatar Oct 05 '18 17:10 kylearoberts

@kylearoberts thanks for the clarification on the calendar invite stuff. Apologies for not getting back to @thinkingserious with some example code. Had to put this on the back burner for a while. I will give this another shot when I have a chance and report back!

coryjamescrook avatar Oct 05 '18 17:10 coryjamescrook

Thanks @coryjamescrook!

thinkingserious avatar Oct 12 '18 17:10 thinkingserious