@alexandrad27705 Restarting the com.day.cq.cq-mailer bundle in the environment was the solution that worked for me.
The MessageGatewayService contains a hashSet of gateways. If you delete or move your Day CQ Mail Service configuration, a new gateway is added to the hashSet. The messageGatewayService.getGateway() only retrieves one DefaultMailService from the hashSet, and it could be one with cfg null inside, although there exists one configured correctly. Only way to clean this up is by restarting the bundle.
Any subsequent updates to theDefaultMailService config work fine. This only happens when you delete/move your config in your environment.
I'm trying with the code in that article. I'm using AEM 6.1 and used my gmail account for smtp configuration. For me, the MessageGateway is not null but it still doesn't send email, it doesn't throw any error either. Wondering how do I debug this further?