sendgrid / sendgrid-go

The Official Twilio SendGrid Golang API Library
https://sendgrid.com
MIT License
983 stars 260 forks source link

Getting error The content value must be a string at least one character in length when 'htmlContent' is set to empty #351

Closed prakashpandey closed 3 years ago

prakashpandey commented 5 years ago

Issue Summary

I am using the code given in the readme doc to send email. My requirement is to send plain text instead of email content. So I used the below code to send email

Steps to Reproduce

var plainTextContent = "some content"
var htmlContent = ""
message := mail.NewSingleEmail(from, e.Subject, to, plainTextContent, htmlContent)

I am getting error :

{
  "errors": [
    {
      "message": "The content value must be a string at least one character in length.",
      "field": "content.1.value",
      "help": "http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.content.value"
    }
  ]
}

Other details

I am able to sent email when htmlContent is a non-empty string. But when I want to send only plain text, why I have to set htmlContent.

I looked into the GoDoc . for func mail.NewSingleEmail() but there is no information there

Technical details:

thinkingserious commented 5 years ago

Hello @prakashpandey,

Please try your use case without using the NewSingleEmail helper, like so.

With Best Regards,

Elmer

prakashpandey commented 5 years ago

Hi @thinkingserious, I went through the link, I think it can solve my use case. I will try and let you know if I face any problems.

But I think the helper NewSingleEmail can be very useful. It's concise and also easy to read and maintain. Is this a bug? If it is, Is there a way I can fix it with a little bit tweaking the code.

Thanks, Elmer!

thinkingserious commented 5 years ago

Hello @prakashpandey,

I think this can fixed by adjusting the NewSingleEmail helper (or create a new one, say NewSingleEmailPlanText helper such that the htmlContent parameter is not required.

We would be thrilled to accept your PR!

With Best Regards,

Elmer

prakashpandey commented 5 years ago

Sure, @thinkingserious I will look into this

thinkingserious commented 5 years ago

Awesome, thank you @prakashpandey!

prakashpandey commented 5 years ago

Hi @thinkingserious, I have raised a pull request. The Travis-ci build is failing. I think it's a test environment issue. Please let me know If I missed something.

Thanks!

thinkingserious commented 5 years ago

Thank you @prakashpandey! Your PR is now in our queue for a code review :)

prakashpandey commented 5 years ago

Hi Elmer (@thinkingserious),

Greetings of the day.

I am now able to send plain text email using this PR fixed locally. But in production, it fails because go get downloads the dependency from here.

Could you please tell me the probable date when the PR can be reviewed and merged?

Thanks, Elmer!

Regards, Prakash

thinkingserious commented 5 years ago

Hello @prakashpandey,

Unfortunately, I don't have a specific date. However, I am planning a release within the next few weeks.

One option is to fork this repo, implement your PR fix and do a go get on the forked repo until we get your PR rolled into the official release.

Another option would be to not utilize the helper until your PR is merged.

With Best Regards,

Elmer