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

SetContentID doesn't actually set content ID for attachments #251

Closed
kevinmu opened this issue Jan 26, 2018 · 7 comments · Fixed by #282
Closed

SetContentID doesn't actually set content ID for attachments #251

kevinmu opened this issue Jan 26, 2018 · 7 comments · Fixed by #282
Labels
difficulty: medium fix is medium in difficulty type: docs update documentation change not affecting the code

Comments

@kevinmu
Copy link

kevinmu commented Jan 26, 2018

Issue Summary

I'm trying to send an email with an attachment, and I am trying to set the content ID for that attachment. However, when I select 'view original' in GMail, it appears that the attachment does not have a content ID set. However, the other fields (content-disposition, filename, etc.) seem to be set correctly.

Steps to Reproduce

func sendEmail() error {
	email := mail.NewV3Mail()
	email.SetFrom(mail.NewEmail("from@from.com", "to@to.com"))
	email.Subject = "Test Email"
	per := mail.NewPersonalization()
	per.AddTos(mail.NewEmail(to.Name, to.Address))
	email.AddPersonalizations(per)

	// Set content
	content := mail.NewContent("text/html", "This is a test.")
	email.AddContent(content)

	// Attach .png file
	pngAttachment := mail.NewAttachment()
	dat, err = ioutil.ReadFile("MY_FILE.png")
	if err != nil {
		fmt.Println(err)
	}
	encoded = base64.StdEncoding.EncodeToString([]byte(dat))
	pngAttachment.SetContent(encoded)
	pngAttachment.SetType("image/png")
	pngAttachment.SetFilename("a1.png")
	pngAttachment.SetDisposition("attachment")

        // this doesn't end up being set :(
	pngAttachment.SetContentID("a1")

	email.AddAttachment(pngAttachment)
	// Send the email
	request := sendgrid.GetRequest(
		"<API_KEY>",
		"/v3/mail/send",
		"https://api.sendgrid.com",
	)
	request.Method = "POST"
	request.Body = mail.GetRequestBody(email)
	response, err := sendgrid.API(request)
	if err != nil {
		println(err)
	} else {
		fmt.Println(response.StatusCode)
		fmt.Println(response.Body)
		fmt.Println(response.Headers)
	}
	return nil
}

Technical details:

  • sendgrid-go Version: 8caf17a (v3.4.1)

  • Go Version: 1.9.2

@thinkingserious
Copy link
Contributor

Hi @kevinmu,

Could you please provide the output of request.Body?

Thanks!

With Best Regards,

Elmer

@thinkingserious thinkingserious added type: question question directed at the library status: help wanted requesting help from the community labels Jan 26, 2018
@kevinmu
Copy link
Author

kevinmu commented Feb 16, 2018

Hey, sorry for the delay. This issue is fixed if you use .SetDisposition("inline") instead of .SetDisposition("attachment"); it was pretty difficult for me to find this, though. I believe I did it through a lot of Googling, as opposed to through any official documentation.

@thinkingserious
Copy link
Contributor

Awesome, thanks for circling back! I'll leave this open so we can update the documentation for clarity.

@thinkingserious thinkingserious added difficulty: easy fix is easy in difficulty up-for-grabs type: docs update documentation change not affecting the code and removed type: question question directed at the library labels Mar 6, 2018
@anchepiece
Copy link
Contributor

Hello @thinkingserious 👋,

Thanks to the sendgrid team for open sourcing this and other projects.

I noticed that there is no mention of the issue on the official v3 docs: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html
It would be nice to confirm that this is really the case for all projects consuming the API in this way.

If there is a need to update ContentID usage here, there are a few places where a notice could help:

Would it also be appropriate to remove SetContentID from any examples when using content disposition "attachment"?

@thinkingserious
Copy link
Contributor

Those are all solid recommendations @anchepiece. I will reserve this PR for you :)

@thinkingserious thinkingserious added status: work in progress Twilio or the community is in the process of implementing difficulty: medium fix is medium in difficulty and removed difficulty: easy fix is easy in difficulty help wanted status: help wanted requesting help from the community labels Oct 2, 2018
@anchepiece
Copy link
Contributor

Thanks @thinkingserious.

Any suggestions or corrections?

@thinkingserious
Copy link
Contributor

I think you are headed in the right direction. Please submit a PR and I'll review it. Thanks!

@childish-sambino childish-sambino removed the status: work in progress Twilio or the community is in the process of implementing label Oct 16, 2020
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 type: docs update documentation change not affecting the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants