Rails ActiveJob/Sidekiq sending emails inconsistently; sometimes sends, sometimes doesn't - ruby-on-rails

I have a Rails 4.2 app using ActiveJob/ActionMailer and Sidekiq/Redis with Devise for authentication. I require email confirmations when signing up, which is handled by Devise. I'm running into an issue when users sign up, but the confirmation email sometimes doesn't get sent.
The logs show that the confirmation email is enqueued by ActiveJob, and sometimes it gets processed, sometimes it does not. When the confirmation email isn't processed, and the user requests for it again, the new confirmation email goes through.
Any ideas as to why this is happening?
Also, I am not iterating over any users, I'm using the standard Devise sign up process. So this doesn't apply.

I think I know the reason for the inconsistent emails. I had two separate staging environments using the same redis server instance. For the sake of explanation I will call them staging1 and staging2.
I believe what was happening was that when a user (ID=1) was being created on staging2, sometimes staging1 would be processing the email for its own user (ID=1), and so the user from staging2 would not get the email, but rather the email was being sent to the user from staging1.
To resolve this issue, one of two things can be done.
Use a separate redis server for each environment.
Use redis namespaces for each environment.

Related

Not receiving email verification link through heroku sendgrid add-on to new sign up gmail account

In my heroku logs the email confirmation link has been sent successfully but didn't received any mail to gmail accountheroku logs
Some code and/or what you configured would help a lot, just the logs does not really give any clue on what's going on.
Make sure you have configured everything correctly for devise (here are some questions already asked that might help you):
Rails devise not sending an email confirmation in development
Rails: Devise not sending confirmation email in production (Heroku)
And I also advise you to not use a gmail account to send emails as they are usually flagged as spam, or sometimes don't even go through at all.

Sending list of emails to a user once they sign up in rails application

I need to send emails to the user who sign up on my system. So, for instance say a user sign up today then after 3 days they should receive one email. Then after 6 days he should receive another email and so forth. There are 8 emails with the interval of 3 days.
I need to run a task where every midnight or every 12 hrs and that task should check whether are there any user who created account in 3,6,9,etc days before. I am aware of Rufus-Scheduler and even it works fine but I am not sure it is good to use it as my production configuration is unicorn and ngninx.I am also using sidekiq in my application for devise async emails.
Is there any other way to implement this or what would be the best way to implement such a system. Thanks in advance for help
My best recommendation would be:
sign up for an account on mailchimp
add the relevant mailchimp gem to your app
when a user signs up to your app, send an API request to mailchimp to subscribe the user
on mailchimp, set up a campaign that has the emails for the user at the required frequency...
don't forget to unsub the user from mailchimp if your user deletes their account on your app
Use mailchimp because you'll get better visibility on open/close rates and it will automatically deal with things like the user wanting to un-sub from your emails (which you are required by law to allow them to do). You also get better ability to do nice things with filtering the list of users eg sending a special email to users that have not yet seen the X email or who opened every email...
You can use reschedule method of sidekiq
Sidekiq::ScheduledSet.new.find_job().reschedule(1.day.from_now)

Custom verification emails

I am trying to create a sort of recall system where an admin sends a message to the entire user base via email after which all users have to confirm the message by navigating a link in the email (Confirmation token) and retyping the message in. The would a submit button on the page which will check if messages match then clears a confirmation flag in the database. I am stuck on where to even begin here. I am not worried about comparison logic in the controller. I am confused about how to generate the confirmation tokens, sending them, then redirecting users to a page for confirmation. At the moment I am use Devise with Active Admin but I am open any other gem suggestions. If any of you could give me a link to a similar tutorial or problem that would be great! Yes I have done research before asking but it most results had little relevance.
U could do this with devise
I'll share what was recently done by me, which is almost similar to your Q.
I did not use Confirmation link or any token.
Only Admin can create user.
On creation of a user, an email is sent along with id and password.
Upon user login for first time, redirect him to edit account for only password change.
Note: U can use friendly token for generating random password.

Devise 3.2, Confirmation without Login, and Password Creation for New Accounts

I've upgraded to Devise 3.2.1 and Rails 4.0, and I'm trying to figure out my signup now that one doesn't login on confirmation.
I allow users to create a message and specify the recipient of the message via an email address. Then I send emails notifying the recipient that they've received a message on the service. If the recipient doesn't have an account on the service, I create the account without a password, and the email I send to the recipient acts a confirmation email. With prior versions, the recipient would then click on the link, thus confirming, and then be taken to a password creation stage and then finally, they'd have a confirmed account created with password and can go see the message.
With Devise 3.1, they no longer allow login via confirmation as they consider it a security risk, however I fear it may greatly increase the complexity of my sign up process. I can no longer redirect to a password creation page as they aren't logged in. I'm toying with the idea of taking them to a special signup page or creating the account and then sending a special form of password reset.
I don't want to notify them via email, then send them a second email as a confirmation. That adds unnecessary complexity to my signup.
I wondered if anyone else has dealt with this issue and how they handled it. I'd like to avoid using:
config.allow_insecure_sign_in_after_confirmation = true
as that will go away soon and is really not the right way.
Is there a secure, yet fast way to do this with Devise 3.2?
Thanks!
I'm switching to using sorcery ( https://github.com/NoamB/sorcery ) for greater control over authentication and building my flow with that.
This is precisely the problem that devise invitable gem solves in a secure manner. I would recommend using this tool, rather than trying to hand-roll your own solution which is more likely to contain security flaws.
The gem workflow is basically:
An admin invites a new user.
The new user is created with a random password. (I actually helped write this bit!)
The user is sent an invitation email. (This is fully customisable in how it works, but has some simple default settings.)
The user receives a link, which contains a URL with a unique invitation_token.
After clicking this link, the user must choose their real password.

How to associate multiple emails for a single user in rails Devise gem

I am developing an application which uses Devise for user authentication. It performs all standard task that Devise handles (e.g.: Email verification during user sign up). But a user may have multiple email addresses to access his account and I want to verify all those addresses too.
My design is: user will get a email field in his profile page to add another email address to access his account along with his existing email address. After clicking submit, an email verification will occur like first time sign up process and user will be able to use both of this email address after successful verification.
Is there any gem available for this? If I need to implement it by myself, how can I do this without breaking the existing system?
It's very late to reply but recently I faced similar issue and found one gem which lets user have many emails, user can login with any email, set one email as primary, and provides support for confirmable, authenticable and validatable for each email.
Here is the link to gem:
https://github.com/allenwq/devise-multi_email
Hope it helps someone facing same situation :)

Resources