Sendgrid-nodejs: custom header for an attachment

Created on 28 Mar 2016  ·  41Comments  ·  Source: sendgrid/sendgrid-nodejs

Hi,

We are using sendgrid to attach iCal (ics) files along with the mail body. We are able to set the content type to “text/calendar” for the ics file, however it is not possible to set additional header "method=REQUEST" which causes the email clients to not recognize the attachment as a calendar event.

Will it be possible to set custom headers for each attachment?

Regards

non-library issue

All 41 comments

Hello @mindnuts,

I'm not sure I understand. Let me make sure I understand:

  1. You have an email with an iCal attachment
  2. You want to add a header to that email (e.g. X-Header: method=Request)
  3. Right now you can not add an additional header. What did you try?

Thanks!

@thinkingserious

While creating the email object we are creating the files array a la and setting "contentType" to "text/calendar" for .ics files. For the ics files to be correctly detected by Outlook the attachment should also have method=REQUEST set in the header.

Content-Type: text/calendar; charset=UTF-8; method=REQUEST

Will this be possible in the sendgrid client?

Can you please share the code that you are using the set this header?

@thinkingserious here you go:

var sendgrid  = require('sendgrid')('YOUR_SENDGRID_API_KEY');

var email = new sendgrid.Email({
  to:       '[email protected]',
  from:     '[email protected]',
  subject:  'Hello World',
  html: 'My first email <b>through SendGrid.</b>',
  text:     'My first email through SendGrid.'
});

email.addFile({
  filename: 'calendar.ics',
  path: './calendar.ics',
  contentType: 'text/calendar'
});

sendgrid.send(email, function(err, json) {
  if (err) { return console.error(err); }
  console.log(json);
});

Here is the header generated by Sendgrid for this attachment:

Content-Disposition: attachment; filename="calendar.ics"
Content-Transfer-Encoding: base64
Content-Type: text/calendar; charset=utf-8; name="calendar.ics"

What i would like to have is (REQUEST is just an example):

Content-Type: text/calendar; charset=utf-8; method=REQUEST; name="calendar.ics"

Thank you, that example is very helpful.

Have you tried to just set the header directly with the headers param?

@thinkingserious I do not want to set the header of the email, i want to be able to set the custom header for the Attachment (.ics file in my case) added to the email.

Regards
M

Thanks for the update, that makes sense.

This will no longer be an issue with the v3 library. For now, the only way you can set that header is through SMTPAPI: https://github.com/sendgrid/smtpapi-nodejs

@thinkingserious Thanks for your response. What is the ETA for V3?

Should be no more than a few months.

@mindnuts,

We are now a few weeks away, you can check out the v3 /mail/send endpoint here: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html and the new version of this library here: https://github.com/sendgrid/sendgrid-nodejs/tree/v3beta

Thanks for your support!

Hello @thinkingserious ,

I guess everyone is still waiting for a solution, so am I !
I'd also like to set method to REQUEST and encounter the problem.

Do you have an update ? It's been 2 months !

Thanks,
Have a nice day,
Jérémy

Hey @thinkingserious ,

I am still locked due to this problem !
Do you have any update ? Any solution ?

Thanks,
Jérémy

Again @thinkingserious do you plan to solve this soon ?
We really need it !

+1

response: {
      "statusCode": 400,
      "body": {
        "errors": [
          {
            "message": "The attachment type cannot contain ';', or CRLF characters.",
            "field": "attachments.0.type",
            "help": "http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.attachments.type"
          }
        ]
      },
      "headers": {
        "server": "nginx",
        "date": "Wed, 01 Mar 2017 04:43:59 GMT",
        "content-type": "application/json",
        "content-length": "216",
        "connection": "close",
        "x-frame-options": "DENY",
        "access-control-allow-origin": "https://sendgrid.api-docs.io",
        "access-control-allow-methods": "POST",
        "access-control-allow-headers": "Authorization, Content-Type, On-behalf-of, x-sg-elas-acl",
        "access-control-max-age": "600",
        "x-no-cors-reason": "https://sendgrid.com/docs/Classroom/Basics/API/cors.html"
      }
    }
}

Am I missing something? What's the proposed solution? why is this closed?

@pascalopitz,

This one should not have been closed. Thanks for the heads up.

Again @thinkingserious are you solving this issue ?!

Hello @ataraxido,

This issue is on the product roadmap, but I don't know when it will be delivered.

Recently, we have received a few new votes for this feature. Whenever that happens, I update the product team to help bump the priority.

With Best Regards,

Elmer

@thinkingserious Just wanted to add that this is a really important feature for us as well. Any update on the product roadmap?

Agreed @hdornier, I'll add your voice to the issue. Thanks for taking the time to vote!

@thinkingserious, you mentioned this can be done with smtpapi. Do you have an example of this? What part of the smtpapi? A simple substitution of some kind?

Hi @e99cog,

I'm not sure why I said that previously :(

I don't know if this will work using the SMTPAPI, but here is an example of how it's used.

With Best Regards,

Elmer

+1 over here also

In the end, I had to resolve this issue by using mailgun and the message.mime endpoint it has, as it allows me to send the mime explicitly.

Does sendgrid offer this feature in any API?

Hey, everyone!

I am Matt, the Developer Experience Product Manager at SendGrid. I am interested in learning more about what you need from MIME types. We typically do this as a google hangout, so that I can learn about your use case and the specifics of what you need.

Please feel free to grab a time on my calendar - https://calendly.com/matt-bernier/mail-send-mime-types

Thanks!!

need to handle this for an upcoming project as well -- is there a status on this? It's been 2 years.

+1
Any ETA for this ?

I'm also very interested in this. Surely, it must be possible to come up with an answer by now.

I don't want to curse things, but a birdy tells me that we are _super_ close to deploying this :) I'll be posting an update here once it's live.

Hello Everyone!

I'm SUPER EXCITED to announce that this issue has been resolved and the fix is live in production! Please give it a try and let me know if you run into any further issue.

Thank you for your patience on this one!

With Best Regards,

Elmer

@thinkingserious That's a great news! Can you help understand what steps to take next? Has support been provided for additional header > method=REQUEST?

Hello @thinkingserious

I just tried and I still get an error ( using the API ) :

{"errors":[{"message":"The attachment type cannot contain ';', or CRLF characters.","field":"attachments.0.type","help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.attachments.type"},{"message":"The attachment type cannot contain ';', or CRLF characters.","field":"attachments.1.type","help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.attachments.type"}]}

Here is what I am doing using the API API :

$attachment->setType('text/calendar; charset="UTF-8"; method=REQUEST');

Are you sure the issue is solved ? What should we do ?

Thanks

@ataraxido it works for me
"attachments": [{ "content": "QkVHSU46....EQVINCg==", "type": "text/calendar; method=REQUEST", "filename": "file1.ics" }]

Returned 202 and mail was sent

Hey @ataraxido you won't need to specify the charset as SendGrid will automatically append this field (same applies for text/html, text/plain). Give it another shot and let us know if that does the trick 🤞

@ataraxido,

Where you able to get it working?

Hello @abhilashabhatia,

Yes, you can now do "type": "text/calendar; method=REQUEST". Please let me know if you run into any issues.

Hello @thinkingserious

I have been able to send the "header" method=REQUEST but I have not been able to send an inline ICS which works fine inside Outlook.
Even in inline with this custom "header" the event reminds an attached ICS.

I think it's pretty broad use case for all your customers ; would you have a working example or an how-to ?

Thanks

+1 to the comment from @ataraxido -- can we get an example @thinkingserious

@ataraxido @tetreault,

Just to clarify, sending as an attachment works in Outlook, but not inline?

This is now on our backlog and I've created an issue in case someone in the community would like to offer a PR.

@thinkingserious actually the ICS is inlined into the email but Outlook considers it as an attachment so it does have the expected behaviour/display of an email inline event.
I'm wondering why, tried many things. I think it could be because you force inline items to be base64 encoded whereas typical ICS inlining is on 7bits.

Hello @ataraxido,

Thanks for the elaboration, I think you might be on to something regarding the encoding.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

agostonbonomi picture agostonbonomi  ·  3Comments

umarhussain15 picture umarhussain15  ·  3Comments

kiranshashiny picture kiranshashiny  ·  4Comments

prasoonjalan picture prasoonjalan  ·  3Comments

thinkingserious picture thinkingserious  ·  4Comments