For sending mail using gmail smtp server, you have to first set access to less secure apps. You can do that here from google's settings. If you don't do that, you get "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required." error.

You can not turn on access to less secure apps if google two step verification is enabled. For sake of code simplicity(Prone to risk), I suggest you should turn off two step verification on your google account and then turn on access to less secure apps.