How to correctly create and setup access_key_id and secret_access_key in Amazon Simple Email Service (SES), for aws-ses gem? In the description of the gem it is written to provide exactly them in the credentials file, but I can't figure out how to create them.
My configuration for aws-ses gem:
# config/initializers/amazon_ses.rb
ActionMailer::Base.add_delivery_method :ses, AWS::SES::Base,
:server => 'email.us-west-2.amazonaws.com',
:access_key_id => Rails.application.credentials.aws[:access_key_id],
:secret_access_key => Rails.application.credentials.aws[:secret_access_key]
I configured the SES service itself by adding my personal domain to it and testing sending emails from the Amazon site. To use the service, it has SMTP settings - but they create a completely different type of key, which is not suitable for the aws-ses gem.
I also tried to use create keys when creating a new user through Identity and Access Management (IAM), specifying full access to Amazon SES.
But all this did not help, the Amazon SES service does not work, and when sending messages to SideKiq, I get errors in the form:
AWS :: SES :: ResponseError: InvalidClientTokenId - The security token included in the request is invalid.
There are several ways to specify credentials for the AWS SDK for Ruby. Hopefully the following topic helps you: https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html
I have a User class that uses devise :confirmable, which, when a user is created, triggers an email to be sent containing a confirmation link. This works perfectly in development and production, but fails in the test environment (Minitest / Capybara). Specifically, clicking the confirmation link results in **Forbidden** You don't have permission to access /users/confirmation on this server.
Screenshot:
Forbidden You don't have permission to access /users/confirmation on this server
Oddly, when I create the user from rails console, just as I do in the integration test, it works. So, why does it fail in the test environment?
Test:
u = FactoryBot.create(:user)
email = ActionMailer::Base.deliveries.last
plain_part = email.multipart? ? (email.text_part ? email.text_part.body.decoded : nil) : email.body.decoded
confirmation_link = plain_part[/<a href="(http:\/\/.*)">Confirm my account<\/a>/,1]
puts "--- #{confirmation_link} ---" # visual check of extracted URL
visit confirmation_link # Forbidden You don't have permission...
save_and_open_screenshot # saves to tmp/capybara/capybara-*.png
And at the console:
require 'factory_bot'
# factory creation code omitted from here
u = FactoryBot.create(:user)
# produces and renders link
Such confirmation links look like this in all environments except test:
http://localhost:3000/users/confirmation?confirmation_token=TxYdRmVzcuPE7PAx7yJh
...and in test they look like this:
http://localhost/users/confirmation?confirmation_token=NqyaVL5EKEnz46zMzDQs
(No port specified in test.)
I am using Rails 5.2.0 with Capybara driver selenium_chrome_headless in these integration tests.
This is because the URL being generated in the email isn't pointing back to the Capybara server. There are a few ways to fix this. The two simplest solutions would be
Fix the port Capybara runs its test server on and set the email generation parameters
Capybara.server_port = 1111 # any fixed port number
# in config/environments/test.rb
config.action_mailer.default_url_options = {:host => 'localhost', port: '1111'} # match whatever server host and port Capybara is running on
Continue allowing Capybara to run on a random port, configure the url generation not to include a port, and set Capybara to always include the server port when no other port is explicitly specified
Capybara.always_include_port = true
# in config/environments/test.rb
config.action_mailer.default_url_options = {:host => 'localhost'} # match the host Capybara is running the test server on
I am trying to setup 'Openproject' management tool in Amazon AWS EC-2 instance. Everything is done and I am able to access openproject home page on entering the IP address of EC-2, but while registering for new user I am getting an error page.
After checking production.log file in the openproject files I am seeing the following error.
Net::SMTPFatalError (553 5.7.1 : Sender
address rejected: not owned by user user#jayrobotix.com
Here are the settings in my configuration.yml file.
default: # Outgoing emails configuration (see examples above)
email_delivery_method: :smtp
smtp_address: smtp.jayrobotix.com
smtp_port: 587
smtp_domain: jayrobotix.com
smtp_authentication: :plain
smtp_user_name: "user#jayrobotix.com"
smtp_password: "password"
smtp_enable_starttls_auto: false
The smtp_user_name and smtp_password is my username and password for my email server.
I am following the manual given in openproject.org website for configuring openproject in linux.
Please help me in setting up this.
..
Thanks
I have some services (say S1 & S2) that I would like to connect them with a third party service (say S3) that uses NTLM authentication. My Problem is that I can use either Basic Auth or Oauth. I was wondering if there is a Proxy that can make this Authentication translation (From NTLM to BasicAuth).
|s1|<--|
|--BasicAuth--> |Proxy| <--NTLM--> |s3|
|s2|<--|
For now, I am using Curl (--ntlm) to achieve that, but I would like to alter this as described.
S1 & S2 are running in a Debian Host.
Cheers!
I manage to Solve that by installing Cntlm. It's a proxy that does pretty much what I described.
I configured the proxy as it is mentioned in this blog post
With the main difference that I set only the Domain, and comment in the Password and User arguments:
Domain mySoapNTLMdomain
# Username
# Password
# NOTE: Use plaintext password only at your own risk
# Use hashes instead. You can use a "cntlm -M" and "cntlm -H"
# command sequence to get the right config for your environment.
# See cntlm man page
# Example secure config shown below.
# PassLM
# PassNT
# PassNTLMv2
So I could be authorised by using Basic Authentication. e.g.
curl http://soap.mydomain:1234/my/path --proxy http://127.0.0.1:3128 --user soapuser:andpass --proxy-user soapuser:andpass
What would be the best way to go about making ActionMailer send mail via Amazon SES in Rails 3?
Edit:
This is now a gem:
gem install amazon-ses-mailer
https://rubygems.org/gems/amazon-ses-mailer
https://github.com/abronte/Amazon-SES-Mailer
Setting up Rails 3.2 for sending emails using Amazon's Simple Email Service (SES) is easy. You do not require any additional gem or monkey patching to make it work.
SES supports both STARTTLS over SMTP as well as TLS/SSL. The following demonstrates how to set up Rails for STARTTLS with SES.
Prerequisites
If you are running rails Mac OS X, you may need to configure OpenSSL for Ruby correctly before you can use STARTTLS. If you are using Ruby 1.9.3 and RVM, here is one way to do this:
rvm pkg install openssl
rvm reinstall 1.9.3 --with-openssl-dir=$rvm_path/usr
If you do not do this, there is a possibility that Ruby will segfault when you try to send an email.
Make sure you have verified your sender email address with AWS. You can only send emails with a verified email address as the sender. Go to the "Verified Senders" option on the left menu in AWS console for SES.
Make sure you have the AWS SMTP user name and password for authentication. Go to the "SMTP Settings" option on the left menu in AWS console for SES to set this up. You will first be prompted to create an IAM user (default: ses-smtp-user) and then you will be shown the SMTP user and password, which look like usual AWS key and secret. Note that the IAM user, i.e., ses-smtp-user is not the SMTP user that you will be using for authentication.
Configuring Rails
In config/environments/development.rb and config/environments/production.rb, add the following:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "email-smtp.us-east-1.amazonaws.com",
:port => 587, # Port 25 is throttled on AWS
:user_name => "...", # Your SMTP user here.
:password => "...", # Your SMTP password here.
:authentication => :login,
:enable_starttls_auto => true
}
Sending an email
This is it. Now you can go ahead and create a mailer and start sending emails for fun and profit!
Create a sample mailer
rails g mailer user_mailer
In app/mailer/user_mailer.rb:
class UserMailer < ActionMailer::Base
# Make sure to set this to your verified sender!
default from: "your#verifiedsender.com"
def test(email)
mail(:to => email, :subject => "Hello World!")
end
end
In views/user_mailer/test.erb:
A quick brown fox jumped over the lazy dog.
Now, launch the console and shoot off a test email:
rails c
Loading development environment (Rails 3.2.1)
1.9.3p125 :001 > UserMailer.test("your#email.com").deliver
I also have a gem out that supports sending e-mail through SES from Rails 3:
https://github.com/drewblas/aws-ses
It also has all the API for verifying/managing e-mail addresses
For TLS SSL setup [Recommended by Amazon SES]
Spoiler Alert: NO GEM Required
smtp is defualt way of sending email in rails but you can add this line to explicitly define in config/application.rb file
config.action_mailer.delivery_method = :smtp
In config/application.rb or you can specify in certain environment file
config.action_mailer.smtp_settings = {
address: 'Amazon SES SMTP HOSTNAME',
port: 465, #TLS port
domain: 'example.com',
user_name: 'SMTP_USERNAME',
password: 'SMTP_PASSWORD',
authentication: 'plain', #you can also use login
ssl: true, #For TLS SSL connection
}
The Amazon SES SMTP HOSTNAME is specific for every region, so you that name which you are in, following are hostnames wrt regions.
email-smtp.us-east-1.amazonaws.com (for region us-east-1)
email-smtp.us-west-2.amazonaws.com (for region us-west-2)
email-smtp.eu-west-1.amazonaws.com (for region eu-west-1)
StackOverFlow |
Amazon-getting-started-send-using-smtp
After poking around a bit I ended up just making a simple class to do this.
https://github.com/abronte/Amazon-SES-Mailer
In rails, you can get the encoded email message:
m = UserMailer.welcome.encoded
AmazonSES.new.deliver(m)
I use the following gem:
https://github.com/aws/aws-sdk-rails
It pulls in the standard aws-sdk, plus allows to set ActionMailer to use AWS SES. Example:
# config/production.rb
# ...
config.action_mailer.delivery_method = :aws_sdk
Configuring your Rails application with Amazon SES
set action_mailer.perform_deliveries to true as it is set to false by default in the development/production environment
config.action_mailer.perform_deliveries = true
then paste this code in your development/production environment
config.action_mailer.smtp_settings = {
:address => ENV["SES_SMTP_ADDRESS"],
:port => 587,
:user_name => ENV["SES_SMTP_USERNAME"],
:password => ENV["SES_SMTP_PASSWORD"],
:authentication => :login,
:enable_starttls_auto => true
}
I created a simple Rails / SES API gem that uses Signature v4 to sign the request. This is best used for transactional emails such as contact us, user registration, etc.
Rails SES API integration gem
Please feel free to improve on it & contribute.
SES just was released into beta today, so I doubt that there is a ready-to-go gem (at least, not that I've seen). You could write a custom module based upon their developer documents:
http://docs.amazonwebservices.com/ses/latest/DeveloperGuide/
using :sendmail, I managed to get all emails to send running apt-get install postfix as root on my AWS machine and using all the default answers.
You can provide delivery method to action mailer in your environment.
config.action_mailer.delivery_method = AmazonSES.deliver
For now you are likely on your own writing the delivery code.