I had a friend told me that before Japan made contact with Westerners, sexuality was free and open. Is this true? Were there monogamous relationships? How was sex viewed by those societies?
Sexuality was relatively open but I don't know about 'free'. It also depends on which time period we're talking about because it obviously varies whether we're talking about the period directly prior to the Meiji Period, which would be the Edo Period, or even further back, such as the Sengoku Period, Muromachi, etc. For example there was a period when polygamous marriages were the norm and women had arguably more sexual currency in a matriarchal rural society, but it wasn't during the Edo Period.
Also, by 'made contact with Westerners' I'm assuming you're referring to the famous Perry arrival, but Japan had numerous contacts with the West for about 300 solid years prior to Perry's arrival. By the time Perry arrived in Japan, the Japanese knew quite a lot more about the West than the West knew about Japan.
Relative to say, 19th century America and Europe, yes, the Edo Period (17th - early 19th century) was a relatively open society with regards to sexuality. For example, homosexuality was generally accepted as a part of life. This is not to say that Tokugawa Japan was some sex egalitarian utopia. The government did legislate homosexual encounters and it was regarded in some circles as negative, because infatuation with a male lover might mean shirking one's duty to one's house (producing heirs, managing the affairs of the household, etc).
Historical Japanese male - male sexual relationships are actually fairly complex, arguably more complex than the male - female sexual relationship, at least from a standpoint of a study of Japanese society. For example, the sexual relationship one might have with a young boy would be different philosophically from the relationship a man would have with a male prostitute, male friend, or even a male relative (!). There were different social implications, factors to the relationship beside sexual contact, etc.
The big thing is that male - male sexual relationships didn't threaten the household in the fact that it could never produce heirs and a male lover could not realistically seize anything from the house, since male - male marriage was not a thing.
As an aside, female - female sexual relationships are a whole other ball game and were considered separate from male - male sexual relationships. As in the concept of a unified 'homosexuality' was non existent in Japanese sexual society before the modern period.
Monogamous marriages between a man and a woman were the norm and infidelity was considered grounds for a divorce, which also leads us into - divorce was also very much a thing, which also points to Japan being a relatively sexually 'free' society. Of course this comes with a ton of caveats, such as legally speaking, women could not initiate divorce. In practice, women had their own methods but the fact was that they were not equally represented legally nor socially whether in sexual relationships or marriage.
It's important to remember that while Japanese women were relatively free compared to their counterparts in other parts of the world, they were still considered inferior to men in Neo-Confucian philosophy, which was tempered by native Japanese beliefs and a less drastic interpretation of Neo-Confucianism compared to the way the movement manifested in China and Korea, where absolute obedience was the only factor.
To paint in broad strokes, sex, particularly men having sex with women, was seen as common and pedestrian. The primary purpose of having sex with one's wife was to produce children. This doesn't mean that all Japanese marriages were loveless affairs with utilitarian sex. There's plenty of literature that points to plenty of men - and women - who enjoyed happy, sexually fulfilling marriages ( as well as marriages where bad sex or lack of sex was seen as a negative ). Either way, sex was not some taboo subject. It was a part of life and was commented on socially, whether in daily conversation, the relationships people pursued, or literature and philosophical ruminations.
At the same time, almost counter intuitively, courtesans, whether female or male courtesans (yes there were plenty of male prostitutes) were often objects of sexual adoration. The prizing of chastity, outside of religious circles (priestesses were virgins), was not really a thing. Religiously speaking, sex can be a way of aligning oneself with kami (gods) in Shinto and a healthy sexual appetite in a marriage is appreciative in cultivating one's kami. But at the same time, lust was seen as impure and some sexual acts were seen as impure (within the context of Shinto metaphysics). For example, masturbation was seen as impure and there were rituals for cleansing one's body of sexual impurities before entering Shinto shrines.
That being said things like engaging in sexual relationships before marriage was not considered negative and sometimes was encouraged outright for girls to 'prepare' for a future wedding night, at least socially speaking.
Infidelity within marriage is a tricky bit. On one hand, infidelity was considered to be wrong and undermining marriages. But at the same time, it was, to a degree, acceptable to have lovers. Society was particularly lenient with visits to prostitutes/courtesans but the prostitutes themselves were seen as seedy and of ill repute, particularly those that catered to the lowest common denominators, ie the middle class and commoners.
Erotic media certainly flourished, with everything from porn, fantastical porn, erotic art, high culture erotic art, sleazy novels, classier romantic literature, etc having a market, being produced and sold openly.
Anyways, I think I hit the biggest points. If you have more questions feel free to ask.
My recommended reading on the topic is as follows:
Cartographies of Desire: Male-male Sexuality in Japanese Discourse by Gregory M. Pflugfelder
Adultery, Punishment, and Reconciliation in Tokugawa Japan by Amy Stanley
Fertility and Pleasure: Ritual and Sexual Values in Tokugawa Japan by William R. Lindsey
EDIT: I wasn't expecting so many follow up questions! This is very exciting but I have work in about 6 hours and need to get some sleep or I'll be crushed tomorrow. Feel free to keep posting questions. I'll respond when I can!! Happy to be of service!
Cheers!