This matter is as complex as it is interesting, so put your mind in low gear and hold on... Here's a drawing to help you keep oriented:

First of all, not every earthworm segment bears sex organs. Counting from the front, the worm's male sex cells lie in segments 10 and 11. From here the sperm pass through sperm ducts to two male genital openings on the bottom of segment 15. On segments 9 and 10 there are two minuscule sacs called sperm receptacles, or pores, where, during earthworm sex, sperm are deposited. However, this is not where eggs are produced. The egg-producing ovaries reside in segment 13, from which eggs are released through the female pores into egg sacs in segment 14. Finally, there's a rubbery, arm-band-like thing covering the worm's body from segments 31 or 32 to 37, and this is called the clitellum.
Now, when two earthworms mate, they line up next to one another with their "heads" pointing in opposite directions. The clitellum of one worm lies opposite segments 9-11 of the other, which, you'll remember, contain the male parts. The worms now secrete tremendous amounts of mucus, until each is enclosed in a slime tube extending from segment 9 to the rear end of the clitellum at segment 37. Now sperm are ejaculated from segment 15 and carried backward in tubes formed by grooves in the body touching the slime tube and the sperm pass to the sperm receptacles on segments 9 and 10 of the other worm.
Then the earthworms go their different ways. Sex is done. However, that is not to say that eggs have been fertilized, because they haven't. It's just that now, in each worm's sperm receptacles, there are sperm from the other worm.
The next step in producing baby earthworms comes when the earthworm is by itself. Its clitellum secretes a second mucous ring that slides forward over the worm's body. When the ring passes the openings in segment 14, several ripe eggs leave the body and stick to the ring. The ring keeps moving forward until it passes the sperm receptacles in segments 9 and 10, and here sperm come into contact with eggs. Finally, within the mucous ring, the eggs are fertilized.
Now the ring containing the fertilized eggs slips off the worm's "head," seals at both ends, and becomes a sort of cocoon, which is left lying in the soil. Ultimately the eggs hatch and tiny worms escape from the mucous ring, into the soil.
Source >>
http://www.backyardnature.net/