mail attachment SendGrid using ruby -


i trying send email attachment in ruby , have following line:

from = email.new(email: 'mail@mail.com') = email.new(email: 'mail@mail.com') subject = 'file week' content = content.new(type: 'text/plain', value: 'please find file week.') mail = mail.new(from, subject, to, content) mail.attachments['test.txt'] = file.read("#{rails.root}/public/test.txt") sg = sendgrid::api.new(api_key:'myapikey') sg.client.mail._('send').post(request_body: mail.to_json) 

the issue code following line (when remove it, receive email):

mail.attachments['test.txt'] = file.read("#{rails.root}/public/test.txt") 

but when try run it, following error:

undefined method '[]=' nil:nilclass

has faced error before?

per docs, create new mail object using hash values being strings. it's hard tell, because don't know email or content classes doing, suspect going wrong when create mail. let's unknown classes out of picture starters.

try changing code to:

from = 'mail@mail.com' = 'mail@mail.com' subject = 'file week' content = 'please find file week.'  mail = mail.new(from: from, to: to, subject: subject, body: content) mail.attachments['test.txt'] = file.read("#{rails.root}/public/test.txt")  sg = sendgrid::api.new(api_key:'myapikey') sg.client.mail._('send').post(request_body: mail.to_json) 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -