Is the Z-spread related to the YTM?

If so, how? The YTM is the rate used to bring all cash flows to a present value that matches its current price right? The Z-spread is similar right?

Not really.

The Z-spread is a constant spread added to each rate on the (usually Treasury) spot curve so that when the cash flows are discounted at the (new, adjusted) spot rates, the present value equals the market price. But each cash flow is still discounted at a (potentially) different rate.

The YTM is a single discount rate applied to all of the cash flows so that the present value equals the market price. There is no spread added to a bond’s YTM.