After the period of Swedish rule the northern part of present-day Latvia became part of Russia. Together with the southern part of present-day Estonia this formed the province of Livonia with Riga as its capital.
The southern part of present-day Latvia, Courland, still belonged to Poland, and after the Third Partition of Poland it went to Russia with Mitau as its capital. The eastern part of Latvia, the Latgale region, came to Russia as part of the province of Witebsk after the First Partition of Poland (1772).
Even then Riga was already a big city, and many entire stationary from Riga exist with cancels from this period. After the German occupation during the First World War Latvia became independent after the war.
The first stamps are very special: printed on the blank back side of German military maps.
On August 5, 1940 Latvia Latvia was incorporated into the Soviet Union and also after the German occupation (1941-1945) Latvia remained a Soviet republic. It was not until August 24, 1990 that Latvia would proclaime its independence again.
In the Soviet Union many covers with imprinted stamp were used, and Latvia also started with issuing an entire on December 24, 1990. On October 19, 1991 the first stamps of once independent again Latvia were issued.
Literature about postal history: here.