Haggai was sent by God to preach to the restored community of Jews in Jerusalem after the Babylonian Captivity had ended. He encouraged his fellow Jews to finish rebuilding the Temple, which had been destroyed by the Babylonians in about 586 BC.
Haggai's messages were addressed to Zerubbabel the governor, and to Joshua the high priest. He began to preach in 520 BC after the work to rebuild the Temple had ceased. The work began anew and the Temple was completed during the next four years (520 BC - 516 BC).
Haggai, along with the prophet Zechariah, Zerubbabel and Joshua, played an important role in getting the Temple rebuilt. The rebuilt Temple (also known as the second Temple) lasted 5 centuries until it was rebuilt by Herod the Great in 20 BC.
Before the Temple had been rebuilt, Haggai drew a link between Judah's poverty and depressed state of affairs and the sinful indifference in regards to rebuilding the Temple.