1. Turn on less secure app access

Login to gmail -> Accounts -> Security and turn on the less secure app access
or access through  https://myaccount.google.com/lesssecureapps

2. Moodle settings

Navigate to Dashboard –> Site Administration –> Server –> outgoing mail Configuration

SMTP Hosts     :   smtp.gmail.com:465
SMTP Security  :   SSL
SMTP Auth Type :   Login
SMTP username  :   <username>
SMTP Password  :   <password>

3. Testing mail server

Navigate to Dashboard –> Site Administration –> Server –> Test outgoing mail server