This is the curse of the 40 degree wash... it's too cool and encourages mould. (Per the washer repair guy we use).
Take out the detergent tray and clean it, lots of black mould accumulates under that, so get a baby bottle brush and go into that area too on the machine. Pour boiling kettle of water down the hatch as well.
I run a 90 degree wash with a good dose of bleach and wash my old towels (used for the dog or spills, etc). I don't do this in an empty machine. I let it run a full two hour cycles, and then give the cycle a double-rinse.
Leave the door open after doing your wash loads, especially if you have an under the counter machine with a cosmetic cabinet door attached. It needs to dry out. Takes at least 2 hours. Never leave wash in a machine more than a few hours. Not overnight for sure.
All other suggestions above are great for maintaining a fresh machine especially to be sure the gasket think does not collect dirt/lint. I use liquid to avoid crusty build up.
We have 4 flats in our building we let to tenants and this washer problem is as bad as bathroom tile/tub/shower tray mould. (They never wipe the edges down and leave bottles of shampoo, conditioner, etc and that make is mouldy.
People need to remember to leave bathroom doors OPEN after finishing showering or bathing. Without windows, extractors do not remove enough of the humidity, and the fan vents get clogged with dust and it sticks to the moisture. So the vents are doing a lousy job as well.
Many single young people today are not particularly household handy with busy working lives. They are tidy enough, but will run a wash and leave it in there for two days. They then complain to me the washer is making their clothes stink...or they complain of the black mould around the tub/shower which just needs a wipe down. It's hard work going up there and ripping out the old silicone and putting in new because the mould has creeped in at the edges. Ugh.
Good luck... unless you machine is really old, you should be able to sort it. Lots of good ideas here.
