Unable to send confirmation mail

Hello,

I have edited my the secrets.yml file to send confirmation mails for user registration (according to the docs). I set the smtp settings and restarted server. But nothing is being sent!

Any idea on how to solve the problem is appreciated.

Thanks

Hi @sfb,

Maybe one of these threads can help you:

If you can’t solve the problem with the help of these threads, I would need some more information.

Perhaps you could check the application logs and see if there is anything that might give us an idea of what is happening to you.

Hello,

Thank you so much for your response.

Now the emails start working, but there is still a problem. After sending two or three email, it fails to send any more, and I need to restart deploy to fix it.

I used gmail smtp for the smtp configuration. Could you please help me on this.

Thank you!

Hi @sfb,

Using gmail smtp should not be a problem

The emails are sent through DelayedJob. Can you make sure that you have DelayedJob started when you send the emails and that it is still running when they are not sent? This way we can discard that it is a problem with DelayedJob.

I recommend that you check the application logs and compare the traces when mails are sent with the traces when no mails are sent. This information may be useful for us to try to help you solve the problem.

Hello,

Thank you for your time and help.

I checked delayed_job.log in both cases: when it sends email and when it doesn’t send it.
When sending email, these three lines are added to the end of log file:

INFO … Job ActionMailer::MailDeliveryJob…from DelayedJob(mailers) with arguments: … (queue=mailers) RUNNING
INFO … Job ActionMailer::MailDeliveryJob… … from DelayedJob(mailers) with arguments: … … (id=85) (queue=mailers) COMPLETED after 1.1596
INFO – : 2022-12-05T12:11:47+0100: [Worker(delayed_job.1 host:98 pid:2956888)] 1 jobs processed at 0.8379 j/s, 0 failed

However, it does not add anything to the delayed_jobs.log whenever emails are failed to be sent.
I used " Delayed::Job.last.last_error" to check the emails error in production e and this was the result:

"uninitialized constant ActionMailer::MailDeliveryJob\nDid you mean? ActionMailer::DeliveryJob\n/home/deploy/consul/shared/bundle/ruby/2.7.0/gems/activesupport-5.2.7.1/lib/active_support/inflector/methods.rb:285:in const_get'\n/home/deploy/consul/shared/bundle/ruby/2.7.0/gems/activesupport-5.2.7.1/lib/active_support/inflector/methods.rb:285:inblock in constantize’ \n/home/deploy/consul/shared/bundle/ruby/2.7.0/gems/activesupport-5.2.7.1/lib/active_support/inflector/methods.rb:281:in `each’\n/home/deploy/consul/shared/bundle/ruby/2.7.0/gems/activesupport-5.2.7.1/lib/active_support/inflector/methods.rb:281:in…

But I could also see this error before correctly configuring the smtp and be able to send my first email.

Thank you.

Hi @sfb,

It seems the ruby code in charge of email sending crashes before writing in the log. It’d be nice having the whole trace. To get it, Can you try sending the failing email through the rails console?

You can do it as follows:

deploy@ubuntu-16gb-nbg1-4 : ~/consul/current $ bin/rails c -e production

Mailer.already_confirmed(User.last).deliver_now

Can you share the exception trace with us?

Best regards

Hello Sendero,

The following is the trace of it:

Rendering mailer/already_confirmed.html.erb within layouts/mailer
Dalli::Server#connect localhost:11211
Rendered mailer/already_confirmed.html.erb within layouts/mailer (Duration: 9.5ms | Allocations: 1709)
Rendered layouts/_mailer_header.html.erb (Duration: 11.8ms | Allocations: 7081)
Rendered layouts/_mailer_footer.html.erb (Duration: 0.3ms | Allocations: 209)
Mailer#already_confirmed: processed outbound mail in 43.0ms
Skipped delivery of mail 638f0eecd121a_2f11892f08207bb@98F9ACC.mail as perform_deliveries is false
Date: Tue, 06 Dec 2022 10:44:12 +0100
From: CONSUL admin@consul.dev
Message-ID: 638f0eecd121a_2f11892f08207bb@98F9ACC.mail
Subject: Your account is already confirmed
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit

Open Government
CONSUL
  </tr>
</tbody>

Your account is already confirmed

We've received a request to send you instructions to confirm your account. However, your account is already confirmed, so there's no need to do so again.

If you've forgotten your password, you can reset it at the following link:

Forgotten your password?

CONSUL

    <p style="font-family: &#39;Open Sans&#39;,&#39;Helvetica Neue&#39;,arial,sans-serif;margin: 0;padding: 0;line-height: 1.5em;color: #222; font-size: 10px; margin-top: 12px;">
      This message was sent from an email address that does not accept replies.
    </p>
  </td>
</tr>

=> #<Mail::Message:274460, Multipart: false, Headers: <Date: Tue, 06 Dec 2022 10:44:12 +0100>, <From: CONSUL admin@consul.dev>, <To: >, <Message-ID: 638f0eecd121a_2f11892f08207bb@98F9ACC.mail>, <Subject: Your account is already confirmed>, <Mime-Version: 1.0>, <Content-Type: text/html>, <Content-Transfer-Encoding: 7bit>>

Thank you for your help.

Hi @sfb,

There is a line in your log that says the following:

Skipped delivery of mail 638f0eecd121a_2f11892f08207bb@98F9ACC.mail as perform_deliveries is false

Probably the last user in your database has no email; when this happens, the class in charge of sending emails skips the delivery of this message. Here is the CONSUL code responsible for this behaviour [1]. Try the command with a user with an actual email.

If this is the trace of the production server, I would also recommend using a FROM email address from within the same domain where the server is running. Now you are using admin@consul.dev as the from address, which could end in your application messages filtered as SPAM. Guess you are running the application in the domain yourcity.com; the application FROM address should belong to that domain, something like noreply@yourcity.com.

I hope this helps.

[1] https://github.com/consul/consul/blob/master/app/mailers/mailer.rb#L163

1 Like