According to Maimonides / רמב"ם (Rambam, Hilchot Avel 14:1), comforting mourners — Nichum Avelim / ניחום אבלים is a rabbinical commandment. However, Rabbeinu Yonah / רבנו יונה writes in his commentary to Talmud, Tractate Berachot 17b that it is one of the scripturally mandated acts of kindness — Gemilut Chasadim / גמילות חסדים.
Greetings. When visitors arrive, the mourners do not rise to greet them. They do not stand up even before the greatest sage of the generation. This is why the front door of the house of mourning usually remains unlocked during visiting hours. The visitors should not greet the mourner with the traditional greetings, but rather they enter the house silently. It is absurd to greet the mourners with the traditional Shalom Aleichem / שלום עליכם — peace be with you, for they are obviously not at peace; or to say “Good Day”, for that day is not good at all to them. The mourners should not greet the visitors either. If a visitor, who is unaware of this prohibition, greets the mourners, they may respond in an undertone, except for during the first three days, when the mourners, in order to avoid bad feelings, simply explain that they cannot respond because of the Shivah / שבעה. It is customary that the visitors do not even greet each other in the house of mourning, especially using the word “Shalom / שלום — peace”.
Gifts. Visitors coming to comfort the mourners do not bring gifts. As a matter of fact, it is forbidden to send gifts to the mourner (even on Purim / פורים!) until twelve months have passed for parents, and thirty days for the other closest relatives. Bringing flowers is viewed as most insensitive, since flowers are associated with festive occasions and not with mourning. However, when somebody does bring a gift the mourner may accept it. Bringing kosher food and other things to provide for the mourner’s family needs are permissible and should be encouraged, especially where it is customary that the guests are served full meals.
When to visit. Some have a custom that during the first two days, only the family members and the closest friends come to comfort the mourner. Other visitors begin coming to pay condolence calls on the third day. The mourners’ friends, neighbors and co-workers are welcome to come — no invitations are needed. One should be considerate of the mourners, though, and not come late at night or in the early afternoon, when the mourners usually rest. Obituary notices or synagogue newsletters may give specific hours when visitors are welcomed. Condolence calls are not usually made on the Sabbath or on the Jewish Holidays, although it is permissible to visit the mourners on these days.
What to say. Silence and introspection are distinctive signs of mourning. Aaron the High Priest was silent, when he learned that his two sons died (Leviticus 10:3). Accordingly, visitors should not begin to speak until the mourner first speaks. The mourner may start the conversation by simply saying, “Blessed is the True Judge.” One should not tell the mourner, “Life goes on”, or “It could have been worse”, or “This is the way of the world — you cannot change it” but rather say, “It is a terrible tragedy, but we should accept His decree with love.” Jokes and small talk are not appropriate during condolence calls. The purpose of a condolence call is not to distract and take the mourner’s mind away from the deceased, but rather to empathize with his or her loss. It is therefore fitting to speak of the good qualities of the deceased. When mentioning the name of the deceased, it is customary to say “Alav HaShalom / עליו השלום — may he rest in peace”, or “Aleha HaShalom / עליה השלום — may she rest in peace”, after the person's name. Alternatively one may say “Zichrono / זיכרונו (for a woman: Zichrona / זיכרונה) LiVracha / לברכה — of blessed memory”.
When leaving, each visitor bids farewell to all the assembled mourners collectively with the traditional formula of consolation. The mourners just answer Amen / אמן and neither say good-bye nor get up to escort the guests.
Condolence letters, emails and telephone calls are fine, but it is questionable if they count as fulfillment of the Nichum Avelim / ניחום אבלים obligation. If one did not have a chance pay a condolence call during the Shivah period, he may express condolences to the mourner up until twelve months have passed for parents, and thirty days for the other closest relatives. After that, one does not recite the traditional formula of consolation, but should simply tell the mourner “May you be comforted”.