简体   繁体   English

Ruby on Rails-Devise向用户电子邮件发送带有登录凭据的欢迎消息

[英]Ruby on Rails - Devise send user email a welcome message with login credentials

After creating a user by admin, a welcome mail should be sent to the user's email address with login credentials ie username (user's email) and password. 通过管理员创建用户后,应将欢迎邮件发送给用户的电子邮件地址,并带有登录凭据,即用户名(用户的电子邮件)和密码。

Can you help me in the smtp settings as well? 您还能在smtp设置上帮我吗?

Thank You! 谢谢!

I needed this functionality once and got it working by creating a method in my mailer 我需要一次使用此功能,并通过在邮件程序中创建一个方法来使其正常工作

def welcome_email(user,password)
        @user = user
        @password = password
        mail(to: @user.email, subject: 'Welcome Email')
    end

In my welcome_email.html.erb : 在我的welcome_email.html.erb

<p>Dear <%= @user.name %>,</p>
<p>  Welcome to this site. Your account has successfully been created. </p>
<p> Please Login to your account</a> using these credentials: </p>
<ul>
  <li>Username: <%= @user.email %></li>
  <li>Password: <%= @password %></li>
</ul>

And call this method from your devise users/registration_controller in create action after creating the user. 并在创建用户后从您的devise用户/ registration_controller中调用此方法以执行create操作。

MyMailer.welcome_email(resource,params[:user][:password]).deliver_later

you might have to change the code according to your needs, but you'll get an idea as from where to start. 您可能需要根据需要更改代码,但是您将获得一个从哪里开始的想法。

For SMTP settings, see this 有关SMTP设置,请参阅

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM