Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

TEHRAN, Iran — Iran's former hard-line President Mahmoud Ahmadinejad sent a letter Sunday to President Donald Trump, striking a somewhat conciliatory tone while applauding immigration to America and saying it shows "the contemporary U.S. belongs to all nations."

It isn't the first dispatch sent by Ahmadinejad, who has counted U.S. Presidents George W. Bush and Barack Obama among his pen pals.

But this letter, weighing in at over 3,500 words, comes as criticism of Trump over his travel ban affecting seven Muslim-majority countries, including Iran mounts in Tehran. It also may serve to burnish Ahmadinejad's image domestically after the nation's Supreme Leader warned him not to run in Iran's upcoming May presidential election.

Related: Iran-Saudi Arabia Is a Relationship With a Troubled History

In the letter, published by Iranian media outlets, Ahmadinejad noted Trump won the election while he "truthfully described the U.S. political system and electoral structure as corrupt."

Ahmadinejad decried U.S. "dominance" over the United Nations, as well as American meddling in the world that has brought "insecurity, war, division, killing and (the) displacement of nations."

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Then Iran's President, Mahmoud Ahmadinejad arrives at the presidential office to attend a welcoming ceremony for his Syrian counterpart Bashar al-Assad, in Tehran, Aug. 2, 2008. Morteza Nikoubazl / Reuters

He also acknowledged the some 1 million people of Iranian descent living in America, saying that U.S. policies should "value respect toward the diversity of nations and races."

"In other words, the contemporary U.S. belongs to all nations, including the natives of the land," he wrote. "No one may consider themselves the owner and view others as guests or immigrants."

A judge later blocked Trump's travel ban, and an appeals court refused to reinstate it. Trump has promised to issue a revised order soon, saying it's necessary to keep America safe.

Entirely missing from the letter was any reference to Iran's nuclear program. Under Ahmadinejad's presidency, Iran found itself heavily sanctioned over the program as Western governments feared it could lead to the Islamic Republic building atomic weapons. Iran has long maintained its program was for peaceful purposes.

Iran under current President Hassan Rouhani struck a nuclear deal with world powers, including the Obama administration, to limit its enrichment of uranium in exchange for the lifting of some sanctions. Trump campaigned promising to renegotiate the deal, without offering specifics.

Ahmadinejad gave the letter to the Swiss Embassy in Tehran, which represents U.S. interests in Iran. The embassy declined to comment Sunday while American officials could not be immediately reached.

The letter comes ahead of Iran's presidential election, in which Rouhani is widely expected to seek a second four-year term. While allies of Ahmadinejad are expected to run, he himself won't after Supreme Leader Ayatollah Ali Khamenei warned him in September his candidacy would bring about a "polarized situation" that would be "harmful for the county."

Ahmadinejad's popularity in Iran remains in question. During his tenure, he personally questioned the scale of the Holocaust and predicted the demise of Israel. His disputed 2009 re-election saw widespread protests and violence. Two of his former vice presidents went to prison for corruption.

But Ahmadinejad offered Trump his own warning about how quickly time passes for leaders.

"Four years is a long period, but it ends quickly," he wrote. "The opportunity needs to be valued, and all its moments need to be used in the best way."

Associated Press writer Jon Gambrell in Dubai, United Arab Emirates, contributed to this report.