使用Rails和Devise,我想在注册时发送欢迎电子邮件。 [英] Using Rails and Devise, I want to send a welcome email on sign up.

查看:131
本文介绍了使用Rails和Devise,我想在注册时发送欢迎电子邮件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注册时如何向用户发送欢迎电子邮件?我正在使用Devise gem进行身份验证。 SMTP已经建立。我只需要了解如何扩展发送电子邮件。

How can I send a welcoming email to the user when they sign up? I'm using the Devise gem for authentication. SMTP is already set up. I just need to understand how to extend devise to send emails.

注意 - 这不是确认电子邮件!

NOTE - this is not confirmation email!

UPD解决方案

class User < ActiveRecord::Base
  after_create :send_welcome_email 

  private

    def send_welcome_email
      UserMailer.deliver_welcome_email(self)
    end
end


推荐答案

在模型或观察者中添加回调(after_create)使用普通邮件方式发送电子邮件。

Add a callback (after_create ) in the model or observer to send the email using normal mailer methods.

这篇关于使用Rails和Devise,我想在注册时发送欢迎电子邮件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆