How to setup Amazon SES with my app on VPS?

In the config there’re only 2 keys related to SES and both are optional

    # Region for the Amazon Simple Email Service, SES. Leave blank if
    # SES not used
    aws_ses_region:

    # Verified email addresses created in SES are subscribed to send
    # complaints and bounces to this SNS topic. Leave blank is SES not
    # used.
    aws_ses_sns_topic:

How to set up? Should I use “mail_delivery_method: smtp”?

Have you checked the docs?
https://github.com/sharetribe/sharetribe/blob/master/docs/using-amazon-ses-with-sns.md

At SES dashboard I have Server Name:

email-smtp.{region}.amazonaws.com

Where should this be specified?

put it in config.yml as smtp_email_address

Also, there are helpful hints in comments for example in https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-php.html

I’ve checked that.

  1. What should be in “smtp_email_domain” - domain of my website? Or some AWS SES domain?

  2. Also, I have “IAM” == ses-smtp-user.123456… and “SMTP Username”. Where shold I put “IAM”?

I have this in config/config.yml:

staging:
  domain: "staging.my_domain123.com"

  mail_delivery_method: smtp
  smtp_email_domain: my_domain123.com
  smtp_email_address: email-smtp.{region123}.amazonaws.com 
  smtp_email_user_name: aabbcc 
  smtp_email_password: ddeejj 
  smtp_email_port: 587 

After I’ve signed up, an email won’t arrive to me.

Where could be an issue?

  1. Emails are sent from background jobs, so check that you also have delayed jobs process running:
    RAILS_ENV=staging bundle exec rake jobs:work

  2. Test emails from rails console to check if your smtp connection is correct:
    PersonMailer.welcome_email(Person.first, Community.first).deliver_now!

I got this:

  NoMethodError: undefined method `locale' for #<Person::ActiveRecord_Relation:0x005560347989b8>
  Did you mean?  lock_value
          from app/mailers/person_mailer.rb:317:in `welcome_email'
          from (irb):7

And this is the code:

  def welcome_email(person, community, regular_email=nil, test_email=false)
    @recipient = person
    recipient = person
    with_locale(recipient.locale, community.locales.map(&:to_sym), community.id) do   #<--- #317

      @current_community = community

Your error message tells that you have passed wrong parameters to mailer, something like

PersonMailer.welcome_email(Person.where(....), ....)

it should be Person.where(...).first or Person.find_by_username('admin') - i.e. single record, not a query

p1 = Person.where(....).first

irb(main):055:0* a1 = PersonMailer.welcome_email(p1, Community.first).deliver_now!
ArgumentError: Error(s) in /home/user123/my_app/app/services/email_service/email_service_injector.rb:21:in `new': sns_topic: Missing mandatory value.
        from app/utils/entity_utils.rb:377:in `block in build'
        from app/utils/entity_utils.rb:423:in `with_result'
        from app/utils/entity_utils.rb:369:in `build'
        from app/services/email_service/ses/client.rb:17:in `initialize'
        from app/services/email_service/email_service_injector.rb:21:in `new'
        from app/services/email_service/email_service_injector.rb:21:in `build_ses_client'
        from app/services/email_service/email_service_injector.rb:13:in `build_addresses_api'
        from app/services/email_service/email_service_injector.rb:3:in `addresses_api'
        from app/services/email_service/api/api.rb:6:in `addresses'
        from app/utils/mail_utils.rb:82:in `community_specific_sender'
        from app/mailers/person_mailer.rb:336:in `block in welcome_email'
        from app/utils/mail_utils.rb:25:in `block (2 levels) in with_locale'
        from app/utils/mail_utils.rb:72:in `set_community'
        from app/utils/mail_utils.rb:24:in `block in with_locale'
        from app/utils/mail_utils.rb:52:in `set_locale'
        from app/utils/mail_utils.rb:23:in `with_locale'
        from app/mailers/person_mailer.rb:317:in `welcome_email

aws_ses_sns_topic is missing

Check section about SNS in docs/using-amazon-ses-with-sns.md

I’ve tried 2 different persons:

irb(main):005:0> a1 = PersonMailer.welcome_email(p1, Community.first).deliver_now!
{"tag":"action_mailer","free":"Delivering email","type":"delivering_email","structured":{"to":[],"from":["aabbcc@my_domain123.com"],"subject":"Welcome to Sharetribe"}}
ArgumentError: SMTP To address may not be blank: []
        from (irb):5

My confing:

staging:
  domain: "staging.domain123.com"

  # AWS keys
  aws_access_key_id: [....]
  aws_secret_access_key: [....]

  mail_delivery_method: smtp
  smtp_email_domain: domain123.com
  smtp_email_address: email-smtp.us-west-2.amazonaws.com 
  smtp_email_user_name: [....] 
  smtp_email_password: [....]
  smtp_email_port: 587

  aws_ses_region: "us-west-2"
  sharetribe_mail_from_address: "aabbcc@domain123.com"
  aws_ses_sns_topic: "arn:aws:sns:[........]"

Ok, so all parts of config are in place, but there are no confirmed emails for users.
You can either update them with SQL like

UPDATE emails SET confirmed_at = NOW()

or try to send different kind of email, like confirmation:

PersonMailer.email_confirmation(Email.last, Community.first).deliver_now!

Thanks. It’s working, but not completely - only emails belonding to my domain will come through.

When I’m using the emails that don’t belong to my domain such as - fdsafdsaf@fdsaf222dsfd.com and that exist in my db - I got this:

Net::SMTPFatalError: 554 Message rejected: Email address is not verified. 
  The following identities failed the check in region US-WEST-2: my_email@my_other_domain456.com

This has to do with my settings at Amazon and not my app, right?

Looks like as if it was trying to use person’s email to authenticate at amazon.

Where can I find logs for email jobs and background ones in general?