He served as a Massachusetts state senator and a U.S. senator , and then , during James Monroe 's presidency , as secretary of state , where he was largely responsible for formulating the principles behind the Monroe Doctrine .
He was never in government .