Comments (14)
I think I was using 3.0.7 .. but let me try 4.0.0 and confirm if this is a definite issue. I'll also provide with the exact error message alongside code shortly.
from sendgrid-ruby.
Awesome, thanks!
from sendgrid-ruby.
ok that worked but I had to switch the lines and put the line with 'text/plain' before the line with 'text/html'...
from sendgrid-ruby.
awesome, thanks!
from sendgrid-ruby.
Hello @34code,
I could not reproduce that error with this code:
require 'sendgrid-ruby'
include SendGrid
require 'json'
def hello_world
mail = Mail.new()
mail.from = Email.new(email: "[email protected]")
mail.subject = "Hello World from the SendGrid Ruby Library"
personalization = Personalization.new()
personalization.to = Email.new(email: "[email protected]")
mail.personalizations = personalization
mail.contents = Content.new(type: "text/plain", value: "some text here")
mail.contents = Content.new(type: "text/html", value: "<html><body>some text here</body></html>")
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.client.mail._("send").post(request_body: mail.to_json)
puts response.status_code
puts response.body
puts response.headers
end
hello_world
What version of the library are you using?
from sendgrid-ruby.
still broken. tested in both 4.0.1 and 4.0.0
error:
App 88244 stdout: 400
App 88244 stdout: {"errors":[{"message":"Invalid type. Expected: object, given: string.","field":"content.0","help":null},{"message":"Invalid type. Expected: object, given: string.","field":"personalizations.0.to.0","help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.personalizations.to"}]}
code used in rails5
template_id = "6ede18bb-2eba-4958-8a57-43a58a559a0a"
from = SendGrid::Email.new(email: '[email protected]')
subject = "App - Reset Password"
per = SendGrid::Personalization.new
per.to = SendGrid::Email.new(email: user.email, name: user.name)
per.substitutions = SendGrid::Substitution.new(key: "user_name", value: user.name.split(" ")[0].capitalize)
per.substitutions = SendGrid::Substitution.new(key: "reset_link", value: some_func(token, email: user.email))
content = Content.new(type: 'text/html', value: 'test')
email = SendGrid::Mail.new(from, subject)
email.personalizations = per
email.contents = SendGrid::Content.new(type: 'text/plain', value: "Hi #{user.name}.. Click the following link to reset your password.. #{function_reset(token, email: user.email)}... This link will expire in two hours.. If you did not request your password to be reset, please ignore this email and your password will stay as it is.")
email.template_id = "6ede18bb-2eba-4958-8a57-43a58a559a0a"
response = @@sg.client.mail._('send').post(request_body: email.to_json)
puts response.status_code
puts response.body
puts response.headers
from sendgrid-ruby.
Please try this:
email = SendGrid::Mail.new
email.from = SendGrid::Email.new(email: '[email protected]')
email.subject = "App - Reset Password"
per = SendGrid::Personalization.new
per.to = SendGrid::Email.new(email: user.email, name: user.name)
per.substitutions = SendGrid::Substitution.new(key: "user_name", value: user.name.split(" ")[0].capitalize)
per.substitutions = SendGrid::Substitution.new(key: "reset_link", value: some_func(token, email: user.email))
email.personalizations = per
email.contents = Content.new(type: 'text/html', value: 'test')
email.contents = SendGrid::Content.new(type: 'text/plain', value: "Hi #{user.name}.. Click the following link to reset your password.. #{function_reset(token, email: user.email)}... This link will expire in two hours.. If you did not request your password to be reset, please ignore this email and your password will stay as it is.")
email.template_id = "6ede18bb-2eba-4958-8a57-43a58a559a0a"
response = @@sg.client.mail._('send').post(request_body: email.to_json)
puts response.status_code
puts response.body
puts response.headers
from sendgrid-ruby.
issue can be closed -- but I hope this helps someone else searching on google as documentation is pretty sparse right now around the new API..
from sendgrid-ruby.
Thanks @34code,
I've added a short term baby step of providing a simple working template example to the docs in the repo to our backlog. I should be able to get that implemented within a few sprints.
Ideally, you should not have to worry about the ordering the content objects. I will address than in the next iteration of the mail helper.
from sendgrid-ruby.
I am getting response like :--
@Body="",
@headers=
{"server"=>["nginx"],
"date"=>["Mon, 10 Apr 2017 13:06:27 GMT"],
"content-type"=>["text/plain; charset=utf-8"],
"content-length"=>["0"],
"connection"=>["close"],
"x-message-id"=>["8mw9nktNSBSGQnrHkXny8Q"],
"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"]},
@status_code="202">
I didn't get why?
from sendgrid-ruby.
Hello @ravirakesh,
That looks like a successful response. Here is a complete list of our status codes.
In this particular case, the 202 status code means that your message is both valid, and queued to be delivered.
The response body should be empty.
The x-message-id
helps you to track this particular message when used in conjunction with our Event Webhook.
Please let me know if you have further questions.
Thanks!
With Best Regards,
Elmer
from sendgrid-ruby.
Hi Elmer,
I have verified that when I am sending mail on send-grid got response but I want to know how to manage object.
example if I send @user.email and using in template then how can i get actual response
Thanks,
Ravishankar
from sendgrid-ruby.
What kind of significance in x-message_id , and we are passing object in json but in response direct object is coming.
{"server"=>["nginx"],
"date"=>["Tue, 11 Apr 2017 13:44:44 GMT"],
"content-type"=>["text/plain; charset=utf-8"],
"content-length"=>["0"],
"connection"=>["close"],
"x-message-id"=>["-ybjzAnqRVSTa9HG-bW9Fw"],
"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"]}
How we can get success response 200 ok, currently I am getting 202 response and we got message from send-grid.
WHY?
from sendgrid-ruby.
Hello @ravirakesh,
You don't really need to do anything with the return object if your email is successfully sent. You will want to save the x-message-id
if you are doing email tracking, but otherwise you can ignore it.
In the case of an error, you will want to do this.
I hope that helps.
- Elmer
from sendgrid-ruby.
Related Issues (20)
- Request: Make it possible to pass http_options config when initialize API HOT 1
- Ruby 3 support HOT 2
- Is sendgrid-ruby still ruby 2.2. compatible? HOT 2
- Unable to verify signature for testing purposes HOT 7
- [BUG] Filter all messages does not work as described in documentation HOT 5
- How to add/remove contacts to a list via new marketing API? HOT 5
- Adding SendGrid addon on Heroku uses Basic Authentication with Username and Password HOT 4
- How to substitute \n or carriage returns HOT 1
- SendGrid::DuplicatePersonalizationError HOT 1
- BaseInterface class should be inside a module HOT 1
- Bad username / password HOT 5
- EML files turning into multiple attachments when using Inbound Parse HOT 5
- Personalization causes duplicate `to` email and sometimes causes multiple emails HOT 1
- Dynamic Templates overwritting list styles HOT 2
- Priority of sent emails HOT 1
- Helpers do not have all properties HOT 1
- The link to be notified of releases and breaking changes is returning a 500 from Heroku HOT 1
- Multiple Emails HOT 3
- uninitialized constant SendgridService::Personalization HOT 1
- Error in ruby documentation for associating authenticated domains with a subuser
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sendgrid-ruby.