Sayyiduna Yazid bin al-Akhnas (may Allah be pleased with him), who had the honour of being a Companion, narrates that the Prophet (peace and blessings be upon him) said: "Envy is permissible only regarding two kinds of men: a man to whom Allah Almighty has given the knowledge of the Qur'an, and he remains occupied with it night and day and follows the rulings it contains, so a man says: 'If Allah Almighty were to give me what He has given so-and-so, I would remain occupied with it just as this person remains occupied with it'; and a man to whom Allah Almighty has given wealth, and that person spends it and gives charity, so a man (who sees him and envies him) says something similar."
This narration was recorded by Imam al-Tabarani in al-Mu'jam al-Kabir, and its narrators are "thiqat" (trustworthy).