We now stock and offer an inexpensive Icotek “split cable gland”. This will allow you to thread the M12 connector end through the cable gland and then tighten the cable gland to make a splash proof seal. We recommend that you point this gland downwards and make a drip loop on the cable to prevent water from running down the cable and attempt to make it through the gland. The gland has ingress protection rating of IP54.
Here is a direct link to the product where you will find images, installation video and specifications.
tek.com/us/product-catalog/cable-glands/qvt/