Bug 38282 - Set ReplytoDefault syspref as the from address for sftp_file.pl
Summary: Set ReplytoDefault syspref as the from address for sftp_file.pl
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Command-line Utilities (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on: 36766
Blocks:
  Show dependency treegraph
 
Reported: 2024-10-28 19:54 UTC by Alex Buckley
Modified: 2024-10-31 00:46 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 38282: Set ReplytoDefault as the preferred from_address of sftp_file.pl (1.91 KB, patch)
2024-10-28 20:43 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 38282: Set ReplytoDefault as the preferred from_address of sftp_file.pl (1.96 KB, patch)
2024-10-30 19:13 UTC, David Nind
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Buckley 2024-10-28 19:54:28 UTC
As per https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=36766#c30 we should set the from_address of the email sent by sftp_file.pl to ReplytoDefault and only fallback to KohaAdminEmailAddress if it is not set.
Comment 1 Alex Buckley 2024-10-28 20:43:22 UTC
Created attachment 173592 [details] [review]
Bug 38282: Set ReplytoDefault as the preferred from_address of sftp_file.pl

Default to KohaAdminEmailAddress if ReplytoDefault is not set

Test plan:
1. Enter a valid email address into ReplytoDefault and
   KohaAdminEmailAddress sysprefs

2. Apply patch and restart services

3. Generate a file on your Koha server. Place it in /tmp/test.mrc

4. Manually connect to the SFTP remote host and accept the hostkey

5. Enter Koha shell

6. Run the sftp_file.pl command-line script
./sftp_file.pl --host <your remote hostname> --user <your user> --pass <your password> --upload_dir <your upload directory> --file /tmp/test.mrc --email <your email>

7. Confirm the SFTP was successful

8. Confirm that the email that you received has a from address matching the
   ReplytoDefault syspref

9. Empty out the ReplytoDefault syspref and repeat steps 5 and 6

10. Confirm that the new email you received has a from address matching
    the KohaAdminEmailAddress syspref

Sponsored-by: Catalyst IT
Comment 2 Alex Buckley 2024-10-28 20:44:12 UTC
Thanks for requesting the follow-up in https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=36766#c30 Katrin!

I've attached the follow-up patch here. Hopefully it does what you are after, if not I can amend it as needed :)
Comment 3 David Nind 2024-10-30 19:13:11 UTC
Created attachment 173739 [details] [review]
Bug 38282: Set ReplytoDefault as the preferred from_address of sftp_file.pl

Default to KohaAdminEmailAddress if ReplytoDefault is not set

Test plan:
1. Enter a valid email address into ReplytoDefault and
   KohaAdminEmailAddress sysprefs

2. Apply patch and restart services

3. Generate a file on your Koha server. Place it in /tmp/test.mrc

4. Manually connect to the SFTP remote host and accept the hostkey

5. Enter Koha shell

6. Run the sftp_file.pl command-line script
./sftp_file.pl --host <your remote hostname> --user <your user> --pass <your password> --upload_dir <your upload directory> --file /tmp/test.mrc --email <your email>

7. Confirm the SFTP was successful

8. Confirm that the email that you received has a from address matching the
   ReplytoDefault syspref

9. Empty out the ReplytoDefault syspref and repeat steps 5 and 6

10. Confirm that the new email you received has a from address matching
    the KohaAdminEmailAddress syspref

Sponsored-by: Catalyst IT
Signed-off-by: David Nind <david@davidnind.com>
Comment 4 David Nind 2024-10-30 19:56:36 UTC
Testing notes (using KTD):

1. Test plan notes:
   . See comment #21 from bug 36766 for notes on how to set up KTD to use an SFTP server.
   . To set up KTD to send email using a Google account, see [1].
   . To receive the emails for step 8 of this bug's test plan (this bug), you need to run misc/cronjobs/process_message_queue.pl

2. Because of the way sending email works when using a Google account (I think), the from address in the actual emails you receive is always the email address for your Google account (the 'User name' setting). 

3. However, if you read the output from running misc/cronjobs/process_message_queue.pl, then the 'From:' address will be the address you set in ReplytoDefault, and if that is empty it will show the address from KohaAdminEmailAddress.

5. So, I think testing with a real SMTP server would have the correct from addresses for the emails you actually receive.

[1] Set up KTD to use a Gmail account for sending email (for testing purposes only)
===========================================================

To test sending emails using a Google account:

1.1 Set up an App password for your Google Account (search the internet for how to do this).

1.2 Edit /etc/koha/sites/kohadev/koha-conf.xml file and add this configuration near the end (where <user_name> = your Google email address; <password> = your APP password, not your Google account password):

 <smtp_server>
    <host>smtp.gmail.com</host>
    <port>587</port>
    <timeout>5</timeout>
    <ssl_mode>STARTTLS</ssl_mode>
    <user_name>GOOGLEACCOUNTUSER</user_name>
    <password>GOOGLEAPPPASSWORD</password>
    <debug>1</debug>
 </smtp_server>

OR (preferred, easiest)

1.3 Configure a new 'SMTP Server' under 'Administration > SMTP servers'
    using the following settings where `User name` = your Google email
    address and `Password` = your APP password, not your Google account
    password:

      Host: smtp.gmail.com
      Port: 587
      Timeout: 5
      SSL: STARTTLS
      User name: GOOGLEACCOUNTUSER
      Password: GOOGLEAPPPASSWORD
      Debug mode: Enabled
      Default server: select
Comment 5 Alex Buckley 2024-10-31 00:30:43 UTC
Hi David, 

Thanks so much for testing. I'm sorry I dont think this follow-up is required after all. I attached the above commit (as a follow-up) onto https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=36766 so Katrin could include it in main. 

So the commit on this bug report should already have been upstreamed. I'll mark this bug report as resolved fixed. Sorry again for not making that clearer here!

Alex
Comment 6 David Nind 2024-10-31 00:46:47 UTC
No worries!