Predicting dust extinction from the stellar mass of a galaxy