In the case of WW1 and WW2, how did they declare war on each other? Did they send a telegram, or just start mobilizing their armies?
It's not a dumb question, but I'm afraid there isn't an easy answer as there were no hard and fast rules that were universally followed in history.
According to The Hague Convention treaty of 1907, which I think most of the countries involved in WWI and WWII signed except Italy, a country must notify another that they have declared war before they attack; or give them an ultimatum that they must meet certain conditions or else a state of war will exist. However, it doesn't say how the country must notify another, except to say that a telegram is considered acceptable; nor how much time they must give before. The Hague Convention also doesn't provide for the safe passage of diplomats between warring states.
Historically the most common thing to happen was that a government would notify the embassy of the country it was declaring war against with a letter or personal meeting, followed shortly after with an expulsion of the diplomatic staff and allowing them safe passage out of the country. Sometimes they would hold up the diplomat's passage until they had a guarantee their own diplomats would be free to come home. During WWI the French felt the Germans tricked them when they let the German embassy staff go, while the Germans held the French staff at the border for many weeks.
Often countries realized that tensions were increasing between their nations and they would recall their diplomats and close their embassy before a declaration of war. In those cases, the county would assign another embassy to send or receive messages on their behalf, usually the embassy of a neutral country such as Switzerland. In 1939 Britain assigned the US embassy in Berlin to handle their affairs.
On December 7, 1941, Japan planned to notify all the countries they were attacking through their embassies in those countries that they had declared war just 30 minutes prior to the attacks. The Japanese ambassador in Washington, DC was to give a written message to Secretary of State Cordell Hull, but the embassy failed to decode the message in time and they didn't deliver it until two hours after Pearl Harbor began. When the US learned that Japan had seized their embassy in Tokyo and held their staff, Roosevelt ordered the Japanese staff be taken into custody. The same happened when Germany and Italy declared war a few days later. The US swapped diplomats with the other countries in 1942.
The Americans always maintained that Japan violated The Hague Convention by failing to notify before the attack on Pearl Harbor and made it an issue at the war trials.