Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The content_id parameter is required if disposition = \'inline\'.' #841

Open
dungahk opened this issue Nov 5, 2018 · 10 comments
Open

The content_id parameter is required if disposition = \'inline\'.' #841

dungahk opened this issue Nov 5, 2018 · 10 comments
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: bug bug in the library

Comments

@dungahk
Copy link

dungahk commented Nov 5, 2018

Issue Summary

Error when trying to send an email with an attachment.

The content_id parameter is required if disposition = \'inline\'.',

Steps to Reproduce

Just try to send an email with attachments and disposition 'inline'.

My code:

send({
  from: { name: 'From Name', email: 'some@email.com' },
  to: { name: 'To Name', email: 'another@email.com' },
  subject: `Some subject`,
  text: 'Email text',
  attachments: [
    {
      content: buffers.pop().toString('base64'),
      filename: fileMetadata.name.split('/').pop(),
      type: fileMetadata.contentType,
      disposition: 'inline',
      contentId: 'my_content_id'
    }
  ]
});

I'm using Typescript and the attachments property is defined as an Array of AttachmentData, which includes a property called contentId, but the API requires the property content_id which is in the interface AttachmentJSON instead.

send function types: https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/mail/src/mail.d.ts#L20

attachments property types: https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/helpers/classes/mail.d.ts#L134

AttachmentData interface types: https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/helpers/classes/attachment.d.ts#L1

Technical details:

  • @sendgrid/mail Version: 6.3.1
  • Node.js Version: 8.11.2
  • TypeScript Version: 3.1.6
@thinkingserious
Copy link
Contributor

Hello @dungahk,

It looks like there is a bug in the AttachmentData interface. I will add this issue to our backlog for a fix as well as tag it for external contribution.

With Best Regards,

Elmer

@thinkingserious thinkingserious added type: bug bug in the library status: help wanted requesting help from the community difficulty: medium fix is medium in difficulty up-for-grabs labels Nov 13, 2018
@sculaste
Copy link

Hi @thinkingserious ,
Is there any updates on this one?

Best regards,
Solomon

@thinkingserious
Copy link
Contributor

Hello @dungahk, @sculaste,

Have you tried using content_id instead of contentId as the key?

With Best Regards,

Elmer

@thinkingserious thinkingserious added status: waiting for feedback waiting for feedback from the submitter and removed help wanted status: help wanted requesting help from the community labels Dec 21, 2018
@kozak-codes
Copy link

Yeah, looks like just a simple typescript error. A simple cast of your object to any is a quick and simple fix until the fix is roled out.
eg:

mail.attachments.push({
	content: logo,
	content_id: 'logo',
	filename: 'logo.png',
	disposition: 'inline',
	type: 'image/png',
} as any);

@childish-sambino childish-sambino added status: help wanted requesting help from the community and removed status: waiting for feedback waiting for feedback from the submitter labels Feb 13, 2020
@childish-sambino
Copy link
Contributor

So the TS definition is correct, but the underlying Attachment class is not being used for de/serialization. When adding attachments, the object needs to be converted to a new Attachment() if it's not already.

@kozak-codes
Copy link

Ah okay. So it looks like there are two classes: AttachmentData and AttachmentJSON

Instead of casting to any like I suggested above you can cast to AttachmentJSON. Alternatively, as @childish-sambino suggested, you use new Attachment({ your attachment data here }). If you do not want to work with classes and just want to define the raw JSON data your mail object can be of type MailJSON.

Using MailData in send is problematic and can be confusing because if you define it without using new Mail(), new Attachment(), or not use the JSON interfaces you'll be missing the critical toJSON() functions. Is there a way to avoid this kind of confusion in the future? Possibly use the type (Mail | MailJSON) instead of just MailData in the send function? Perhaps we could convert properties to camel_case in the send function?

@childish-sambino
Copy link
Contributor

I meant that the underlying JS that adds the attachment to the Mail class should work similar to what's done when adding personalizations: https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/helpers/classes/mail.js#L255

But I don't have a strong opinion on which way to go here.

@kozak-codes
Copy link

Ah yes that would work considering the mail service already generates a Mail object if it isn't that class already. That object then calls setAttachments, setPersonalizations, etc. This would need to be done on most other classes as well. I'll see if I have time to submit a PR 🤩.

@thinkingserious
Copy link
Contributor

Since there has been no activity on this issue since March 1, 2020, we are closing this issue. Please feel free to reopen or create a new issue if you still require assistance. Thank you!

@Cafezinho
Copy link

Any updates on this issue? Typescript keeps bothering when using "content_id"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

7 participants