how setup mail server

I have trouble with my internet. It working only some hours on day.
Is possible to install mailer server for forvarding my email when the internet appear?

I would like to send email everytime. If the internet is on machine and when is disconected.
When internet is enabled i send my email and receive email from my mailbox (free like gmail or yahoo or