I have set up my smtp environment like this:
setpref('Internet','SMTP_Server',email_server);
setpref('Internet','E_mail',email_address);
setpref('Internet','SMTP_Username',email_user);
setpref('Internet','SMTP_Password',access_token);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.port','587');
props.setProperty('mail.smtp.starttls.enable', 'true' );
props.setProperty('mail.smtp.starttls.required','true');
props.setProperty('mail.smtp.ssl.enable','true')
props.setProperty('mail.smtp.user',email_address);
props.setProperty('mail.smtp.host','smtp.gmail.com');
props.setProperty('mail.smtp.port','587');
props.setProperty('mail.smtp.auth.mechanisms',['XOAUTH2']);