Devise email custom 'from' parameter based on logged in user - ruby-on-rails

I have an app in which companies can add customers. Each company has its own email.
Currently, when a new customer is created, they receive devise emails (confirmation, password reset etc.) through our domain email, but I want to the customers to see the email as being sent from the one specified by the company instead.
How can I intercept these emails and set the from parameter?

Read this article. It describe how to create custom mailer for Devise.
Inside of your custom mailer you can assign appropriate values to from field.

Related

When does Devise actually send reconfirmation emails?

I'm trying to add email confirmation to a model called "Project" in a Rails app: users should be able to set an email address for a project, which is not saved until they click a confirmation link sent to the email address provided.
Although I have no need for its authentication features, I thought the Devise gem might be useful. I was hoping to use :reconfirmable to implement the feature: when the user tries to save an email to the project, it instead is saved to the unconfirmed_email column until they confirm.
It appears, partly, to be working -- the database is updated correctly, a token is generated, the "confirmation_sent_at" field is set. But no email template is rendered (and no email is sent). Looking at the code path in lib/devise/models.rb I can see how, before the email field is saved to, a method is called that intercepts that save and instead saves to unconfirmed_email. But where is the email send actually triggered? What do I have to do to activate it?
Assuming that you have correctly configured Devise to use the :confirmable feature and configured your email properly (as described in this answer). Then it should be as simple as calling this:
user.send_confirmation_instructions # where user is one of your Devise users
At the very least, making the send_confirmation_instructions call should show that the email is sending in the Rails log. If that is the case but you don't ever receive an email then you have your email configured incorrectly.

Invite new user to website per e-mail

I would like to build a form on my website where users, who are already registered, could invite new users via e-mail to sign up for this website. The user who sent the invitation and the user who accepted the invitation (and signed up) are then connected through a "friendship" relationship.
I would like to send the invitations via the ActionMailer.
My problem is: How do I "link" the email to the friendship-relationship. One way is probably to create a unique sender_id, which points to the user and which will be used as a link in the email.
Is there another possibility?
Thanks for your help!
In the link create an argument, where you can pass an ID that could identify your relationship.
Something like: http://example.com/invite?abcd
Than in you controller you can treat the relationship.
Other option is to use Devise Invitable

Does devise work with multiple email_id with same account ??

Devise is a fantastic gem available for basic or omniauth authentication sign_up and other things like sessions maintenance, resend confirmation password etc .
But is it possible using devise to map multiple email addresses to same user ?
Like I have 3,4 email ids such as
sahil#abc.com
sahil#xyz.com
sahil#mno.com
Use Case and Example
I have already registered with my first email id i.e. sahil#abc.com using an automated system and account is created. But i always prefer to use my other email_id i.e. sahil#xyz.com. So, i want to build a system where user can login using any one of the above email adresses with the same/different password. But there should be one single account for the user.
I'd say:
you've one email field
you have other emails stored somewhere
You could tell Devise that you allow login based on different fields.
I think the cooler way is to give a try to override the 'authentication_keys' method, as it allows you to define the keys.
But how ever , following link has a working solution :)
HTH
Here is what i exactly needed RoR Devise: Sign in with username OR email
def self.find_for_database_authentication(conditions={})
(self.find_by_email(conditions[:email])) || (AuthorizedEmail.confirmed.find_by_email(conditions[:email]).user if AuthorizedEmail.confirmed.find_by_email(conditions[:email]).present?)
end
What it does is :
Firstly tries to find the user record for authentication by searching with email id.
If it gets the record it returns the record else we go to next part.
It finds in the authorised emails table if there exists any validated and confirmed email in the table. If there is such an entry, it tries to find the user related to that particular authorised email and returns that.

Sending custom email message on devise user creation

So I need to send a confirmation email every time a user signs up. There are two ways of signing up -- either when a user hits my login page, or when he is invited by another user. In both cases, I want to send separate types of email (in the second case, I also want to tell them that you were sent invitation by foo#bar.com person etc.). What is the best way to do this? I am using devise for rails.
use action mailer for sending email
you can send email by using callback means that if you user sign up then below method call
after_create :send_mail_to_xxx_xxx
def send_mail_to_xxx_xxx
...
...
end

Send custom confirmation email in Devise depending on role defined in the database

I am using Devise for registration of a site with confirmable. However, I have two different roles for this site. The first role is the "main" role that uses the regular Devise signup procedure. Accounts in a second role are supposed to be created after the original user confirms their account, logs in for the first time and saves a certain model. For example, if a user signs up for the site (as role type 1) the get a confirmation email from Devise as normal. Next, they visit the confirmation link, verify their account and then fill out a form where they specify some friends that should also get accounts. The friends are role type 2 and they should get a different confirmation email than the original person who signed up their friends for the account. The accounts for the friends are created when the form filled out by the original user is saved. In addition, a person can edit and add more friends later so accounts might also need to be created on the update method of the relevant form/object and those new users will need to be sent the correct email. To be clear, I do not want to skip confirmation - I just want to send different confirmation emails to the user depending on their roles. I cannot figure out how to handle this properly. If I try to create the friends accounts in code when the form is saved with User.new, calling user.skip_confirmation! will automatically confirm them. However, I do not want anyone automatically confirmed - I just want to select a different customizable confirmation email to send depending on various conditions. Can someone point me in the right direction?
Check out send_on_create_confirmation_instructions method and comments for it in your /gems/devise-x.x.x/lib/devise/models/confirmable.rb

Resources