Connecting iMac 2012 to an Yamaha Amplifier
Yes the iMac have optical out, most Macs do.

You need one of these Toslink adapter that plugs into standard 3.5mm audio plug for iMac to output optical from that.

Those are pretty cheap, and most are bundled with the cable itself or some audio accessories. Some shops might give away one for free, I got mine that way.

Anyway, Good luck!