Your question is partly physical chemistry (electrochemistry) and partly biochemistry, and both suggest the question is off-topic and should be moved to either the [Chemistry SE][1] or some Biology or Medicine site (I think the Biology SE got closed).

But since you ask:

When you contact together different metals you will generally find that electrons will move from one metal to the other so one metal will be oxidised and the other metal will be reduced. Because we have electron flow there must be a potential difference between the metals, and this potential difference is called the [electrode potential][2].

The situation in the mouth will be complicated because the aluminium foil will be covered in aluminium oxide, and the mercury in the filling is present as an amalgum (typically with silver) and will probably be coated with mercury compounds. A plausible reaction would be:

$$ 2Al + 3HgO + 3H_2O \rightarrow 2Al(OH)_3 + 3Hg $$

If this is the right reaction then from the list of [standard electrode potentials][3] the electrode potential for this reaction would be about 2.2V or more than an AA cell. However Google has failed to find me any actual measurements so you should regard this as a guideline at best.

Even though the voltage is quite high the actual currents are likely to be extremely small since the reaction will be very slow. At a guess, and it is only a guess, I'd be very surprised if the current generated could do any harm. You need to consult a biologist for a more informed answer.

Whether it is relevant or not I don't know, but I note that aluminium and mercury enthusiastically form an amalgum with each other (though the reaction requires unoxidised aluminum and is slowed by the aluminium oxide layer). This may enahnce the electric contact between the aluminium foil and amalgum filling and maybe enhance the current and therefore the pain.

  [1]: http://chemistry.stackexchange.com/
  [2]: http://en.wikipedia.org/wiki/Electrode_potential
  [3]: http://en.wikipedia.org/wiki/Standard_electrode_potential_%28data_page%29