The SMTP server is used to send mail.
(Note: There are two locations you must paste you app-specific password, these instructions are for the 'sending' server, not the 'receiving' server')
Go to Google and generate an app-specific password on this page.
Now open Mail and go to Preferences > Accounts and select your Google account. At the bottom of the right hand pane it will say "Outgoing Server (SMTP):" and should have "Gmail" selected/ Click on this and you get a pop up menu and select "Edit SMTP Server List".
(This accounts area is where you paste in your 'recieving' password under 'incoming mail server'. Incoming server should be: imap.gmail.com, your username should be the start of your email address without the '@gmail.com' section and your password should be the app-specific password, NOT the account password that was previoulsy used)
This will open a list of the SMTP servers you have set up for sending mail. Click on the "Gmail" one and then click on "Advanced".
Set Authentication to "Password" enter your Google user name then the app-specific password you generated in the password field.
This should now work until you revoke the password.