Closed rohandey closed 3 years ago
Hello @rohandey,
Yes, the method of authentication has changed.
My recommendation is to update to the latest version of this library, then your code would look something like this:
require 'sendgrid-ruby'
include SendGrid
from = SendGrid::Email.new(email: 'test@example.com')
to = SendGrid::Email.new(email: 'test@example.com')
subject = 'Sending with Twilio SendGrid is Fun'
content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
mail = SendGrid::Mail.new(from, subject, to, content)
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.client.mail._('send').post(request_body: mail.to_json)
With best regards,
Elmer
Hi @thinkingserious Thank you, this worked. What is the best way to sets headers under this SendGrid::Mail.new(from, subject, to, content)
Thanks Rohan
Hi @thinkingserious
To be more clear I am not able to do add_tos to message. Previously we were sending news letters by appending array of emails like this
header = Smtpapi::Header.new header.set_tos(email_arr) mail = SendGrid::Mail.new( smtpapi: header, to: 'to@example.com', from: 'from@example.com', subject: 'Daily Mail', html: @template )
sending = @client.send(mail)
What would be the new way with the current api?
Thanks Rohan
Ah, you may need a more flexible approach. Please see this full example. Or, this example, if you would like to use dynamic templates.
Thank You @thinkingserious ... It worked :)
Issue Summary
Using this old sendgrid-ruby version for a legacy app, suddenly it started to throw error SendGrid::Exception: {"errors":["Bad username / password"],"message":"error"}
Is there any change to how api calls are made or we need to make some changes for this work again.
Code Snippet
Exception/Log
Technical details:
Urgent help required.
Thank You