rnwood / smtp4dev

smtp4dev - the fake smtp email server for development and testing
BSD 3-Clause "New" or "Revised" License
3.1k stars 346 forks source link

Saving settings throught the web UI fails #898

Closed bveldkamp closed 3 years ago

bveldkamp commented 3 years ago

When changing a setting in the web user interface and clicking Save, I get an error: Request failed with status code 500.

afbeelding

I checked if this could be a permission issue, and granted full permissions on the Smtp4Dev folder to the DefaultAppPool, but that didn't help.

I then used Process Monitor to see what's going on, and noticed that some non existing paths are used, e.g. E:\Applications\Smtp4dev\smtp4dev\smtp4dev.

12:50:44.8293493 PM w3wp.exe    4444    QueryOpen   E:\Applications\Smtp4dev\api    NAME NOT FOUND  
12:50:44.8294053 PM w3wp.exe    4444    QueryOpen   E:\Applications\Smtp4dev\api\web.config PATH NOT FOUND  
12:50:44.8294435 PM w3wp.exe    4444    QueryOpen   E:\Applications\Smtp4dev\api\Server PATH NOT FOUND  
12:50:44.8294645 PM w3wp.exe    4444    QueryOpen   E:\Applications\Smtp4dev\api\Server\web.config  PATH NOT FOUND  
12:50:44.8370525 PM w3wp.exe    4444    NotifyChangeDirectory   E:\Applications\Smtp4dev        Filter: FILE_NOTIFY_CHANGE_FILE_NAME, FILE_NOTIFY_CHANGE_DIR_NAME, FILE_NOTIFY_CHANGE_ATTRIBUTES, FILE_NOTIFY_CHANGE_SIZE, FILE_NOTIFY_CHANGE_LAST_WRITE, FILE_NOTIFY_CHANGE_CREATION, FILE_NOTIFY_CHANGE_EA, FILE_NOTIFY_CHANGE_SECURITY, FILE_NOTIFY_CHANGE_STREAM_NAME, FILE_NOTIFY_CHANGE_STREAM_SIZE, FILE_NOTIFY_CHANGE_STREAM_WRITE
12:50:44.8370693 PM Rnwood.Smtp4dev.exe 5504    CreateFile  E:\Applications\Smtp4dev\smtp4dev\smtp4dev  NAME NOT FOUND  Desired Access: Read Data/List Directory, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Open No Recall, Attributes: D, ShareMode: Read, Write, AllocationSize: n/a
12:50:44.8371252 PM Rnwood.Smtp4dev.exe 5504    CreateFile  E:\Applications\Smtp4dev\smtp4dev\smtp4dev\appsettings.json PATH NOT FOUND  Desired Access: Generic Write, Read Attributes, Disposition: OverwriteIf, Options: Sequential Access, Synchronous IO Non-Alert, Non-Directory File, Open No Recall, Attributes: n/a, ShareMode: Read, AllocationSize: 0
12:50:44.8371486 PM w3wp.exe    4444    QueryOpen   E:\Applications\Smtp4dev\app_offline.htm    NAME NOT FOUND  

The logfile: stdout_20210917104351_4444.log

Smtp4Dev version is win-x64-3.1.3.2 Windows is Server 2012

jafin commented 3 years ago

The log mentions System.IO.DirectoryNotFoundException: Could not find a part of the path 'E:\Applications\Smtp4dev\smtp4dev\smtp4dev\appsettings.json does that file exist?

bveldkamp commented 3 years ago

@jafin No, Smtp4dev is installed in E:\Applications\Smtp4dev. The subfolder smtp4dev\smtp4dev does not exist, I have no idea where that comes from.

FWIW E:\Applications\Smtp4dev\appsettings.json does exist

jafin commented 3 years ago

@bveldkamp can you run the application via the exe ok and perform the save function? (outside of a hosted app pool?)

bveldkamp commented 3 years ago

@jafin Yes, running the app standalone works, and saves settings to %APPDATA%\smtp4dev\appsettings.json

jafin commented 3 years ago

@bveldkamp I setup the app under IIS on Windows 10. I can see the same error you reported when saving settings. This is not ideal, but if you create a subfolder smtp4dev\smtp4dev in the smtp4dev installation then it will allow the settings to save, if the Apppool account has permission to write to that folder.

For example, I copied the distribution to c:\iis\smtp4dev I then create the folder c:\iis\smtp4dev\smtp4dev\smtp4dev In the app, Save settings, it should write an appsettings.json to c:\iis\smtp4dev\smtp4dev\smtp4dev\appsettings.json The IIS AppPool executing the website must have write permission to that folder.

I think this can be tidied up a bit in the app, there should be no need for the app to have this path created.

bveldkamp commented 3 years ago

@jafin Thanks, that is OK as a workaround. I hope this can be fixed sometime though.