sendgrid / sendgrid-nodejs

The Official Twilio SendGrid Led, Community Driven Node.js API Library
https://sendgrid.com
MIT License
3k stars 781 forks source link

custom header for an attachment #217

Closed mindnuts closed 6 years ago

mindnuts commented 8 years ago

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

thinkingserious commented 8 years ago

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!

mindnuts commented 8 years ago

@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?

thinkingserious commented 8 years ago

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

mindnuts commented 8 years ago

@thinkingserious here you go:

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

var email = new sendgrid.Email({
  to:       'someon@gmail.com',
  from:     'someone@xyz.com',
  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"
thinkingserious commented 8 years ago

Thank you, that example is very helpful.

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

mindnuts commented 8 years ago

@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

thinkingserious commented 8 years ago

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

mindnuts commented 8 years ago

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

thinkingserious commented 8 years ago

Should be no more than a few months.

thinkingserious commented 8 years ago

@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!

ghost commented 8 years ago

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

ataraxido commented 7 years ago

Hey @thinkingserious ,

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

Thanks, Jérémy

ataraxido commented 7 years ago

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

pascalopitz commented 7 years ago

+1

pascalopitz commented 7 years ago
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?

thinkingserious commented 7 years ago

@pascalopitz,

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

ataraxido commented 7 years ago

Again @thinkingserious are you solving this issue ?!

thinkingserious commented 7 years ago

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

hdornier commented 7 years ago

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

thinkingserious commented 7 years ago

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

e99cog commented 7 years ago

@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?

thinkingserious commented 7 years ago

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

aleksandergasna commented 7 years ago

+1 over here also

e99cog commented 7 years ago

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?

mbernier commented 7 years ago

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!!

tetreault commented 6 years ago

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

kszepieto commented 6 years ago

+1 Any ETA for this ?

klogeaage commented 6 years ago

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

thinkingserious commented 6 years ago

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.

thinkingserious commented 6 years ago

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

abhilashabhatia commented 6 years ago

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

ataraxido commented 6 years ago

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

kszepieto commented 6 years ago

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

Returned 202 and mail was sent

roncanada commented 6 years ago

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 🤞

thinkingserious commented 6 years ago

@ataraxido,

Where you able to get it working?

thinkingserious commented 6 years ago

Hello @abhilashabhatia,

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

ataraxido commented 6 years ago

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

tetreault commented 6 years ago

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

thinkingserious commented 6 years ago

@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.

ataraxido commented 6 years ago

@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.

thinkingserious commented 6 years ago

Hello @ataraxido,

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

padapada09 commented 2 years ago

Hi, this issue should not be closed. It only works for "text/calendar; method=REQUEST". Any other combination i.e. "application/ics; method=REQUEST" or even "text/calendar; method=REQUEST; Content-Transfer-Encoding: base64" will not work. Apart from that, the original problem of SendGrid not having the use case of sending a calendar invite remains the same. The only way you can send an invite throw SendGrid is if you define it as a custom content:

await sgMail.send({
            to: "recipientEmail",
            subject: "Invitación",
            templateId: "yourTemplateId",
            dynamicTemplateData: yourTemplateData,
            content: [
                {
                    type: "text/html",
                    value: "<h1>Your email html</h1>",
                },
                {
                    type: "text/calendar; method=REQUEST",
                    value: Buffer.from(event).toString("utf-8"),
                },
            ],
            from: {
                name: "YourName",
                email: "your@email.com",
            },
        });

This however will not allow you to use templates, which I believe is core functionality.

Sorry if this is not the repository I should post this on, it's not clear where should I post this.

Please, I bealive is not hard to contemplate this use case. Allowing to send custom content alongside a template would be enough.

P.D. Happy new year 🎉

nacholupotti commented 2 years ago

same problem that padapada09.

Can you have a look on this?

I am using dynamic templates, and my particular interest is to use the combination of
type: "text/calendar; method=REQUEST" and type: "text/calendar; method=CANCEL" in the attachments section.

Here is the code:

    attachments: [
        {
            content: Buffer.from(event).toString("base64"),
            type: "text/calendar;method=CANCEL",
            filename: "invite.ics",
            disposition: "attachment",
        },
    ],

While using this combination in attachment, the ics is not being rendered.