The main source of vitamin D is via UVB radiation; typically this is from the sun, but less than 5% of sun is UVB.
Sunlight is a good source of vitamin D depends on the time of year and where you are in the world.
There are several studies that suggest that vitamin D can help with depression, however there seems to be significant criticism of those studies. A meta-analysis of those studies1 seemed to see a correlation between the two, but not enough to recommend vitamin D as a universal treatment.
- Vitamin D, via Wikipedia