我想用Amazons(ActionMailer)设置Devise忘记密码电子邮件

时间:2017-09-07 13:43:35

标签: ruby-on-rails amazon-web-services devise

我正在尝试为设计设置重置密码电子邮件,但我的项目使用亚马逊而不是ruby中的默认邮件程序。我怎样才能改变这个?

谢谢!

更新

我已使用config.mailer = "AmazonMailer"连接AmazonMailer现在这是我的邮件程序的样子

class AmazonMailer < Devise::Mailer

  helper :application # gives access to all helpers defined within `application_helper`.

  include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`

  default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views 

    # require 'sendgrid-ruby'
    # include SendGrid

    # def send_email(subject, body, to_email, from_email)

    #   from = Email.new(email: "#{from_email}")
    #   to = Email.new(email: "#{to_email}")
    #   content = Content.new(type: 'text/html', value: "#{body}")

    #   mail = Mail.new(from, subject, to, content)

    #   personalization = Personalization.new
    #   personalization.to = to
    #       #personalization.custom_args = CustomArg.new(key: obj_type, value: obj_id)
    #       mail.personalizations = personalization

    #       puts mail.to_json

    #       sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'] || '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', host: 'https://api.sendgrid.com')
    #       response = sg.client.mail._('send').post(request_body: mail.to_json)
    #       puts response.status_code
    #       puts response.body
    #       puts response.headers
    #   end


    require 'aws-sdk'
    require 'json'

    # Overrides same inside Devise::Mailer
    def reset_password_instructions(record, token, opts={})


    end


    def self.send_email(subject, body, from_name, from_email, to_email, source)

    client = Aws::SES::Client.new

        resp = client.send_email({
            destination: {
                bcc_addresses: [], 
                cc_addresses: [], 
                to_addresses: [to_email]
            }, 
            message: {
                body: {
                    html: {
                            charset: "UTF-8", 
                            data: body
                            }, 
                    text: {
                            charset: "UTF-8", 
                            data: ""
                        } 
                    }, 
                subject: {
                            charset: "UTF-8", 
                            data: subject
                        } 
                    }, 
            reply_to_addresses: [from_email], 
            #return_path: "", 
            #return_path_arn: "", 
            source: source, 
            #source_arn: ""
            })

        resp['message_id'] unless !resp && !resp['message_id']
    end
end

在我的邮件程序中我想覆盖从亚马逊发送的reset_password_instructions方法而不是默认方法。

0 个答案:

没有答案