Is it permissible to give a gift of a ham to a gentile? This could be purchased online and sent directly to them.
Most likely inadvisable; may actually depend on the terms and conditions of the company from which you're ordering. Thanks to NJM for pointing to an essay from Rabbi Moshe Dovid Lebovits of Kof-K kosher; in turn citing Rabbi George Lintz, Journal of Halacha and Contemporary Society volume 24.
Rambam, end of Chapter 8 of Laws of Prohibited Foods:
ח,טז לפיכך אין עושין סחורה לא בנבילות, ולא בטריפות, ולא בשקצים, ולא ברמשים. [יז] הצייד שנזדמנו לו חיה או עוף ודג טמאין וצדן, או שניצודו לו טמאין וטהורין--מותר למוכרן; אבל לא יכוון מלאכתו לטמאין.
Therefore we do not do business with animals that were not kosher slaughtered, with animals that had serious injuries, or with non-kosher species of animals. A trapper who happened to trap a non-kosher type of animal, fish, or bird, or trapped a mix of kosher and non-kosher species -- he is allowed to sell off the non-kosher ones; but he should not set out to make his living from the non-kosher ones.
A ham fits very clearly in this last category: a.) it is prohibited to eat, b.) you may occasionally gift or sell one if it somehow wound up in your possession unintentionally; c.) but you should not decide to go into the ham business.
So is it b.) or c.)? Shach YD 117:3 writes that for me to go buy a ham (or the like) and take it home with intention of gifting it to a non-Jew is like taking it home with intention of selling it to non-Jews; that would therefore be considered "doing business with it" and therefore prohibited.
So what about ordering one for delivery? Chasam Sofer YD104 was asked about a Jew in Trieste going to a seafood market, choosing some barrels of preserved non-kosher seafood, and having them sent on a boat down to Egypt to some non-Jewish partners, billing it to the company. After much deliberation, it ultimately comes down to whether at any moment the Jew was responsible for the wares. Was there a point in time when, if lightning struck the barrels and they went up in smoke, it would have been the Jew's loss? If so, he was trading in non-kosher seafood.
Thus the question becomes: if that ham were to disappear during shipping from the store to its recipient, would I have to pay to have a new one sent? If so, that proves I bought the ham, which would be prohibited. If instead the ham company would pay for another one, it would be allowable as that shows I never really owned this ham.
Rabbi Lebovitz explains,
Food items which are forbidden to do business with on a d’oraisa level (like ham is forbidden in the torah) may not be given to a non-Jew as a present. The reason is because giving a present is like doing business. If one sent the gift directly to the goy (without actually acquiring the gift) some say that this may not be considered buying non-kosher. (Journal of Halacha and Contemporary Society 24:page 96)