You cannot use Gmail, it has nothing to do with the code, has to do with using relay's, almost know popular email will allow the use of relays anymore.
Your settings
Pop.gmail.com
smtp.gmal.com
securessl
Port - 995
port 465
But does not matter anymore.
Your best bet is to use outlook controls or a email provider who allows relays