In the classic series, the episode " By Any Other Name " features aliens from the Andromeda Galaxy.
In Next Gen, they end up in galaxy M33 in " Where No One Has Gone Before ".
Bonus answers: By Any Other Name: It was a 300-year journey, so one presumes "the hard way", at a high warp speed.
Where No
Has Gone Before - enabled by the Traveler (and Wesley, I guess?), and his "magic" powers.
UPDATE:
The androids from I, Mudd were created by beings from the Andromeda galaxy.
scifi.stackexchange.com/users/1150/Chris B. Behrens
Along with the other answers, Voyager introduced the Caretaker and his mate Suspiria, which are beings from another galaxy.
scifi.stackexchange.com/users/2242/Izkata
Memory Alpha has a list of Extra-galactic species , although not all have been "encountered".
scifi.stackexchange.com/users/224/MPelletier
Of course, The Enterprise was TRYING to leave the galaxy in " Where No Man Has Gone Before ", but the Galactic Barrier made things go all kablooie.
In " By Any Other Name " the beings from the Andromeda Galaxy makes reference to this barrier and Kirk rather snidely waves him off: "Yes, I know, we've been there!"
It's one of my favorite Kirk moments.
scifi.stackexchange.com/users/3441/Jordan Hoffman
In the original series episode, "By Any Other Name", visitors from the Andromeda Galaxy attempt to steal the Enterprise to return home.
It seems like there was a TNG or later episode that might have had visitors from another galaxy.
I thought it might have been "The Nth Degree" but the aliens in that episode were from the center of the Milky Way.
scifi.stackexchange.com/users/3147/jfrankcarr
In season 3 episode 26 of Star Trek Voyager, Species 8472 is referred to as being from "outside of our galaxy" (they're probably also outside of our universe, since they're from fluidic space).
The Borg used a modified deflector array to open a rift in space to invade fluidic space from the Delta quadrant, and since they were unable to assimilate the Undine, the creatures counterattacked into our galaxy.
scifi.stackexchange.com/users/3447/sXe
TOS Season 2
" Catspaw ":
Sylvia takes an interest in Kirk and decides to learn more about human feelings and experiences.
Kirk feigns romantic interest, promising to fulfill her desires and be her loyal servant.
She responds by changing into three different but attractive forms to test his emotions.
Kirk tries to subtly extract information from her while he has her charmed, and learns that Sylvia and her partner Korob are explorers, but not from this galaxy .
scifi.stackexchange.com/users/4118/Wayfaring Stranger
Tin Man, AKA Gomtuu may have been "born" outside of our galaxy:
Gomtuu was a living spaceship who seemed to have been "born" far from Federation space, possibly in another galaxy.
Like a traditional starship, Gomtuu possessed a warp drive, transporter capability, and was fully equipped to defend itself.
However, much of its technology was beyond that known to Federation science.
Upon its discovery it was dubbed "Tin Man" by Starfleet and the "Star Creature" by the Romulans. From Memory Alpha As far as the "bonus", Tin Man transversed the distance over the course of millennia.
scifi.stackexchange.com/users/20538/Jolenealaska
The Star Trek universe is set inside our own Milky Way, however has there been any instances of contact with life outside our own Milky Way? I understand the distance between our galaxy and the next is much bigger than distances typically traveled by warp capable ships but there could have been other means of communication or travel.  Edit: Bonus question, how was such a vast distance traveled?
Has there been any contact with life outside our own Milky Way in the Star Trek universe?
scifi.stackexchange.com
<star-trek>
scifi.stackexchange.com/questions/7003
scifi.stackexchange.com/users/3431/Sam152
In Next Gen, they end up in galaxy M33 in " Where No One Has Gone Before ". Voyager introduced the Caretaker and his mate Suspiria, which are beings from another galaxy. Also, in season 3 episode 26 of Star Trek Voyager, Species 8472 is referred to as being from "outside of our galaxy". There are multiple instances of contact with beings from outside of the milky way galaxy. A specific reference point being the episode " By Any Other Name" where the enterprise is a target for the Andromeda species, which come from outside of the Wilkyway. There are also reference to the main crew ending up in other galaxies, such as galaxy M33, and meeting up with species from different galaxies like the Voyager's.
The episode " By Any Other Name" is a staple episode for being from the Andromeda galaxy being introduced. In next gen they end up in a galaxy other than the milky way i.e. galaxy M33 The voyager have been introduced to the series and are a race from outside of the milky way galaxy.