Mary overcomes her depression finally visits Max in New York City, with her newborn son in tow, only to discover that he had died peacefully early that morning. She sits next to his lifeless body, and is happy to discover he saved all her letters and other mementos from their years of correspondence, and had died gazing at her writings. We can hear Max's voice telling Mary that she was his best and only friend.
The film is narrated by Barry Humphries, aka Dame Edna (though not in his alter ego's voice) and takes place in the 1970s.
Mary Daisy Dinkle (voiced by Toni Collette) is a very young Australian girl with a rough life. Her dad is an absent-minded factory worker and her mother is a stay-at-home drunk. She also has a poop-colored birthmark on her forehead and her only friend is an elderly man with agoraphobia. After being told by her grandfather that babies are born at the bottom of a beer can, she decides to choose a random American out of a phone book and write to them to ask where US babies come from. She ends up writing to an older, obese, Jewish man named Max Jerry Horrovitz (voiced by Philip Seymour Hoffman) with a slight mental disability (later dicovered to be asperger syndrome. Like Mary, Max lives a largely solitary life with only an elderly woman as a friend. Though each letter Mary sends to Max gives him day-long anxiety attacks, and Max's letters contain inappropriate subjects for a young girl (such as things about condoms, mental illness, or prostitutes), the two bond over their social awkwardness, love for chocolate, and adoration of a particular children's TV show.
Things go well until Mary falls for her next-door-neighbor, Damien (voiced by Eric Bana) and sends Max a letter filled with questions about sex and love. Max has never been able to understand love or sex due to his mental illness, and has such a severe anxiety attack that he is hospitalized and subjected to electro-therapy. He spurns Mary and refuses to write to her after his hospitalization, causing her self-esteem to evaporate. She had saved money to visit Max by delivering fliers throughout town, but spends it on plastic surgery to remove her birthmark, though the birthmark's removal does not make her any more popular. Max ends up winning the lottery a short time later, and uses his money to complete two of his three life goals - 1) buying a lifetime supply of chocolate and; 2) buying every figurine of the characters from the TV show he and Mary like. His third and final goal was to have a real friend, but has since decided that imaginary friends and pets are safer. He gives his remaining winnings to his elderly neighbor friend, who ends up squandering it with selfish endeavors before dying.
After being arrested for accidentally killing a mime (his AC unit falls out of the wall and crushes the mime), Max decides to get back in touch with Mary, as he finally realises that having a friend who understands him is better than not having one. He writes and explains he has aspergers, but is now taking medications to control his anxiety. He explains that he enjoys that she accepts him for who he is, saying he is happy with his mental illness, lifestyle, and friendship with her. He says he only wishes he could better express his emotions. Mary is overjoyed to have him back in her life, and his letters restore her self-confidence. To help Max, she sends him a jar of her tears that he can dab on his own eyes when he feels sad. She goes to college and studies mental illness so she can better understand Max, and is highly successful. Though both her parents die prematurely (her father is washed away by a wave while using a metal detector on the beach, and her mom in a drunken fit at the news accidentally drinks a lethal amount of embalming fluid), she is able to start a relationship with Damien who she eventually marries. As it turns out, Damien has a pen pal of his own who lives in New Zealand.
Eventually, Mary writes a book about her experiences with Max, and it is hailed by her teachers as an important look into the world of aspergers. She sends a pre-release copy to Max, saying she hopes she can one day find a "cure" for him. Despite his medications, Max devolves into a fit of rage - having told Mary earlier he did not want to be cured and he also feels betrayed that she is sharing his life with the world. Unable to express himself, he simply rips the letter "M" out of his typewriter and mails it to Mary. She realizes she has made a grave mistake, and decides to destroy all her books pre-distribution, effectively ending her career. She sends Max an apology, but he does not accept it, and Mary sinks once again into depression and begins drinking constantly, just as her mom used to. She alienates Damien, and one day she awakens to find a letter from him explaining that he is actually gay and has moved to New Zealand to marry his pen pal.
Eventually, Max realizes that all people are imperfect, just as he himself is. He immediately decides to once again rekindle his friendship with Mary, and sends her a new letter accompanied by his entire collection of figurines from the TV show they both love. The package arrives, but Mary is too drunk to answer the door to accept the delivery, and the box is left on her doorstep. Having been fully abandoned, Mary prepares to hang herself, not knowing that she is pregnant with Damien's child. At the last minute, she answers a knock on the door and answers it, discovering that her agoraphobic friend had finally conquered his fear and exited his house for the first time in decades. She finds Max's package and finally accepts her imperfections. Max has written that she is not only his best friend, but his only friend.
After a year, Mary has fully recovered and is a mother. She has finally flown to New York to visit her lifelong friend. When she arrives, however, she finds that Max has died peacefully on his couch earlier that morning, looking up to the ceiling. As she looks around the room, she finds he had saved every one of the mementos she sent him over the years, including her bottle of tears. She sits next to her dead friend and looks up, only to find that Max had posted all of her letters on his ceiling and had passed away while looking up at them. Before she leaves his apartment, she replaces the "M" back into his keyboard.
We see the NYC skyline twinkling brightly at night, and hear Max's statement that Mary was his best and only friend.