LINCnil / pia-back

Programme développé avec le framework RubyOnRails mettant à disposition une API RESTful à destination des outils PIA et PIA-APP. | Program developped with RubyOnRails providing a RESTful API for the PIA and PIA-APP applications.
GNU General Public License v3.0
156 stars 65 forks source link

Email configuration #199

Closed Foxi352 closed 11 months ago

Foxi352 commented 1 year ago

Hi,

I installed PIA backend and frontend with authentication. Debian 11 using Apache2. Everything works well, except that i can't get pia-back to send emails.

Postfix is installed and working. I tried sending the mail as user www-data and got the mail without problems.

echo "This is the body of the email" | mail -s "This is the subject line" test@xxxxx.xxx

But i do not receive any emails from PIA. The below example is when i user "Récupération du mot de passe":

pia-back access.log:

10.24.0.240 - - [24/Jan/2023:10:27:28 +0100] "OPTIONS /users/password-forgotten HTTP/1.1" 200 3516 "https://pia.xxx.xxx/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.2 Safari/605.1.15"
10.24.0.240 - - [24/Jan/2023:10:27:28 +0100] "POST /users/password-forgotten HTTP/1.1" 500 510 "https://pia.xxx.xxx/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.2 Safari/605.1.15"
10.24.0.240 - - [24/Jan/2023:10:27:35 +0100] "-" 408 3047 "-" "-"

Nothing in mail.log except:

Jan 24 10:19:49 pia postfix/smtpd[6372]: connect from localhost[::1]
Jan 24 10:19:49 pia postfix/smtpd[6372]: disconnect from localhost[::1] ehlo=2 starttls=1 quit=1 commands=4

.env file in pia-back root:

MAILER_SENDER=noreply@pia.xxx.xxx
DEFAULT_URL=https://pia.xxx.xxx
DEFAULT_PORT=443

production.log:

[403b31df-1621-41a0-a7c9-1fc91441fdc4] ArgumentError (SMTP From address may not be blank: nil):

Do i need to configure anything more ? Why is the from address blank, shouldn't it use the MAILER_SENDER env variable?

Thanks for any hint / doc that could help.

brunto commented 1 year ago

Hello @Foxi352, We just merged the rails7 branch to the main branch. Same for "pia" https://github.com/LINCnil/pia with some fixes.

Regarding the SMTP configuration you need to update the information inside: https://github.com/LINCnil/pia-back/blob/master/config/initializers/mailer.rb

The wiki is not updated for now, but you need to set your SMTP credentials in this file. We can help you if needed.

Foxi352 commented 1 year ago

Thanks for your reply. I am new to ruby so updating pia-back, rails and gem's was not that easy :-) Pia was easier as i have Angular experience.

I now have latest versions of pia and pia-back running.

Re mail: If i edit mailer.rb directly, will that not make problems on future git pull ? Can i use EDITOR='nano' bin/rails credentials:edit and put something in there like:

smtp_address: srvexchange.xxx.xxx
smtp_post: 587
smtp_authentication: false
smtp_enable_starttls_auto: true

Or where does it get it's Rails.application.credentials.smtp_address from ?

brunto commented 1 year ago

Yes it's better to update the credentials with EDITOR='nano' bin/rails credentials:edit and set the value inside.

Foxi352 commented 1 year ago

I still get the error production.log:

F, [2023-02-01T14:23:20.526919 #229398] FATAL -- : [b7a116d1-c259-4c59-88bb-315d554eab29]
[b7a116d1-c259-4c59-88bb-315d554eab29] ArgumentError (SMTP From address may not be blank: nil):
[b7a116d1-c259-4c59-88bb-315d554eab29]
[b7a116d1-c259-4c59-88bb-315d554eab29] app/controllers/users_controller.rb:70:in `password_forgotten'

In .env:

MAILER_SENDER=noreply@pia.xxx.xxx

In EDITOR='nano' bin/rails credentials:edit:

smtp_address: srvexchange.xxx.xxx
smtp_post: 587
smtp_authentication: false
smtp_enable_starttls_auto: true

Did i miss something ?

brunto commented 1 year ago

Hi @Foxi352 sorry for the late answer. You need to add email_from into the credentials. You have more information in the README