We show that the resolution of social dilemmas in random graphs and scale-free networks is facilitated by imitating not the strategy of better-performing players but, rather, their emotions. We assume sympathy and envy to be the two emotions that determine the strategy of each player in any given interaction, and we define them as the probabilities of cooperating with players having a lower and a higher payoff, respectively. Starting with a population where all possible combinations of the two emotions are available, the evolutionary process leads to a spontaneous fixation to a single emotional profile that is eventually adopted by all players. However, this emotional profile depends not only on the payoffs but also on the heterogeneity of the interaction network. Homogeneous networks, such as lattices and regular random graphs, lead to fixations that are characterized by high sympathy and high envy, while heterogeneous networks lead to low or modest sympathy but also low envy. Our results thus suggest that public emotions and the propensity to cooperate at large depend, and are in fact determined by, the properties of the interaction network.