Reputation: 4887
I am trying to write a script in my Rails 4.2 application that will send an email using the Amazon SES API using the Ruby SDK version 1. For compatibility reasons with other gems, I need to use Version 1.
The problem that I am experiencing is that when I load the console with rails c
I am able to execute these methods perfectly:
ses = AWS::SimpleEmailService.new
ses.identities.map(&:identity)
ses.send_email(.......)
so on and so forth. However, my script/amazon_ses.rb file seems to fail when I try to execute it and I'm not sure why that is.
Here is my initializer file:
ActionMailer::Base.add_delivery_method :amazon_ses,
AWS::SimpleEmailService,
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
region: 'email.us-east-1.amazonaws.com',
server: 'email.us-east-1.amazonaws.com'
This is my script/amazon_ses.rb
file:
require 'aws-sdk-v1'
ses = AWS::SimpleEmailService.new
identity = ses.identities.map(&:identity)
ses.send_email(.......code.....)
rescue in block in define_attribute_getter': unable to find the identity (AWS::Core::Resource::NotFound)
I'm not sure what to make of this but I have the feeling that Core::Resource is not being loaded, inherited, included etc. Has anyone encounted this problem before?
Upvotes: 0
Views: 169
Reputation: 20232
try adding
require File.expand_path('../../config/environment', __FILE__)
to the top of your script. This will pull in your rails environment.
or without adding the above try
bin/rails runner script/amazon_ses.rb
Upvotes: 1