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 i.e. username (user's email) and password.
Can you help me in the smtp settings as well?
Thank You!
ruby-on-rails ruby devise smtp admin
add a comment |
After creating a user by admin, a welcome mail should be sent to the user's email address with login credentials i.e. username (user's email) and password.
Can you help me in the smtp settings as well?
Thank You!
ruby-on-rails ruby devise smtp admin
add your code to the question, please
– DaFois
Nov 15 '18 at 9:09
2
This is typically a bad idea. Not always, but usually. Presumably you want the admin to change their password after first logging in (otherwise their password is in plain-text in an email!!) -- which begs the question, why bother sending them a password in the first place? By default, devise will send a link with an "invitation token" which only grants initial login once, and then requires the user to set a password.
– Tom Lord
Nov 15 '18 at 9:32
Emailing passwords to users in plain text is not a great security practice. You should consider creating a random password for the user, then using Devise's recoverable module to generate a password reset token. You can then send the user a link to a page that allows them to create their own password using the devise token.
– A_rayB
Nov 15 '18 at 9:38
1
@A_rayB Creating a user with a random password, then "recovering the account", is a weird workaround. There are better libraries for doing this, such asdevise_invitable
.
– Tom Lord
Nov 15 '18 at 13:21
@TomLord yeah you are totally correct. It's been a while since I've had to implement that workflow and I'd forgotten about devise_invitable.
– A_rayB
Nov 15 '18 at 13:53
add a comment |
After creating a user by admin, a welcome mail should be sent to the user's email address with login credentials i.e. username (user's email) and password.
Can you help me in the smtp settings as well?
Thank You!
ruby-on-rails ruby devise smtp admin
After creating a user by admin, a welcome mail should be sent to the user's email address with login credentials i.e. username (user's email) and password.
Can you help me in the smtp settings as well?
Thank You!
ruby-on-rails ruby devise smtp admin
ruby-on-rails ruby devise smtp admin
edited Nov 15 '18 at 9:42
mbuechmann
3,02121428
3,02121428
asked Nov 15 '18 at 9:00
Soumya PoolakkilSoumya Poolakkil
1
1
add your code to the question, please
– DaFois
Nov 15 '18 at 9:09
2
This is typically a bad idea. Not always, but usually. Presumably you want the admin to change their password after first logging in (otherwise their password is in plain-text in an email!!) -- which begs the question, why bother sending them a password in the first place? By default, devise will send a link with an "invitation token" which only grants initial login once, and then requires the user to set a password.
– Tom Lord
Nov 15 '18 at 9:32
Emailing passwords to users in plain text is not a great security practice. You should consider creating a random password for the user, then using Devise's recoverable module to generate a password reset token. You can then send the user a link to a page that allows them to create their own password using the devise token.
– A_rayB
Nov 15 '18 at 9:38
1
@A_rayB Creating a user with a random password, then "recovering the account", is a weird workaround. There are better libraries for doing this, such asdevise_invitable
.
– Tom Lord
Nov 15 '18 at 13:21
@TomLord yeah you are totally correct. It's been a while since I've had to implement that workflow and I'd forgotten about devise_invitable.
– A_rayB
Nov 15 '18 at 13:53
add a comment |
add your code to the question, please
– DaFois
Nov 15 '18 at 9:09
2
This is typically a bad idea. Not always, but usually. Presumably you want the admin to change their password after first logging in (otherwise their password is in plain-text in an email!!) -- which begs the question, why bother sending them a password in the first place? By default, devise will send a link with an "invitation token" which only grants initial login once, and then requires the user to set a password.
– Tom Lord
Nov 15 '18 at 9:32
Emailing passwords to users in plain text is not a great security practice. You should consider creating a random password for the user, then using Devise's recoverable module to generate a password reset token. You can then send the user a link to a page that allows them to create their own password using the devise token.
– A_rayB
Nov 15 '18 at 9:38
1
@A_rayB Creating a user with a random password, then "recovering the account", is a weird workaround. There are better libraries for doing this, such asdevise_invitable
.
– Tom Lord
Nov 15 '18 at 13:21
@TomLord yeah you are totally correct. It's been a while since I've had to implement that workflow and I'd forgotten about devise_invitable.
– A_rayB
Nov 15 '18 at 13:53
add your code to the question, please
– DaFois
Nov 15 '18 at 9:09
add your code to the question, please
– DaFois
Nov 15 '18 at 9:09
2
2
This is typically a bad idea. Not always, but usually. Presumably you want the admin to change their password after first logging in (otherwise their password is in plain-text in an email!!) -- which begs the question, why bother sending them a password in the first place? By default, devise will send a link with an "invitation token" which only grants initial login once, and then requires the user to set a password.
– Tom Lord
Nov 15 '18 at 9:32
This is typically a bad idea. Not always, but usually. Presumably you want the admin to change their password after first logging in (otherwise their password is in plain-text in an email!!) -- which begs the question, why bother sending them a password in the first place? By default, devise will send a link with an "invitation token" which only grants initial login once, and then requires the user to set a password.
– Tom Lord
Nov 15 '18 at 9:32
Emailing passwords to users in plain text is not a great security practice. You should consider creating a random password for the user, then using Devise's recoverable module to generate a password reset token. You can then send the user a link to a page that allows them to create their own password using the devise token.
– A_rayB
Nov 15 '18 at 9:38
Emailing passwords to users in plain text is not a great security practice. You should consider creating a random password for the user, then using Devise's recoverable module to generate a password reset token. You can then send the user a link to a page that allows them to create their own password using the devise token.
– A_rayB
Nov 15 '18 at 9:38
1
1
@A_rayB Creating a user with a random password, then "recovering the account", is a weird workaround. There are better libraries for doing this, such as
devise_invitable
.– Tom Lord
Nov 15 '18 at 13:21
@A_rayB Creating a user with a random password, then "recovering the account", is a weird workaround. There are better libraries for doing this, such as
devise_invitable
.– Tom Lord
Nov 15 '18 at 13:21
@TomLord yeah you are totally correct. It's been a while since I've had to implement that workflow and I'd forgotten about devise_invitable.
– A_rayB
Nov 15 '18 at 13:53
@TomLord yeah you are totally correct. It's been a while since I've had to implement that workflow and I'd forgotten about devise_invitable.
– A_rayB
Nov 15 '18 at 13:53
add a comment |
1 Answer
1
active
oldest
votes
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
:
<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.
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
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315698%2fruby-on-rails-devise-send-user-email-a-welcome-message-with-login-credentials%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
:
<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.
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
add a comment |
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
:
<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.
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
add a comment |
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
:
<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.
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
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
:
<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.
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
answered Nov 15 '18 at 9:11
Saqib ShahzadSaqib Shahzad
612420
612420
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315698%2fruby-on-rails-devise-send-user-email-a-welcome-message-with-login-credentials%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
add your code to the question, please
– DaFois
Nov 15 '18 at 9:09
2
This is typically a bad idea. Not always, but usually. Presumably you want the admin to change their password after first logging in (otherwise their password is in plain-text in an email!!) -- which begs the question, why bother sending them a password in the first place? By default, devise will send a link with an "invitation token" which only grants initial login once, and then requires the user to set a password.
– Tom Lord
Nov 15 '18 at 9:32
Emailing passwords to users in plain text is not a great security practice. You should consider creating a random password for the user, then using Devise's recoverable module to generate a password reset token. You can then send the user a link to a page that allows them to create their own password using the devise token.
– A_rayB
Nov 15 '18 at 9:38
1
@A_rayB Creating a user with a random password, then "recovering the account", is a weird workaround. There are better libraries for doing this, such as
devise_invitable
.– Tom Lord
Nov 15 '18 at 13:21
@TomLord yeah you are totally correct. It's been a while since I've had to implement that workflow and I'd forgotten about devise_invitable.
– A_rayB
Nov 15 '18 at 13:53