The myth of the seven colors from the rainbow is due to Isaac Newton. While he discovered that the colors from sunlight can be decomposed using a prism, he thought there were six, then seven distinct colors. He associated it to superstitions about the number seven, to the 7 musical notes, and probably to some religious beliefs.
Colors can be defined, essentially, in two manners.
- Physics say that there is a "line" of colors that we can see, from red to blue, with infinitely many colors in between. And there are actually colors before red (infrared) and after blue (ultraviolet), that we cannot see. You can also combine many colors from this "line", and to make white, you need all the colors together.
- Our eyes (for most humans) have 3 different detectors, associated to three primary colors, red, green, and blue. All colors we see are a combination of those. Other animals may have a different number of color detectors. But for humans, you must mix red blue and green light to make white-looking light.
To answer your original question, the Sun does not emit 7 colors only, but all visible colors (almost equally). Other stars do the same, but sometimes with different proportions. They can be stronger towards the red or the blue end of the spectrum.