My code now looks like this:
GmailApp.sendEmail(address, subject, body, {htmlBody : body});
- Add the profile scope to your project by editing the appscript.json manifest file.
{
...
"oauthScopes": [
"https://www.googleapis.com/auth/userinfo.profile"
],
...
}
- Add a function that will retrieve the current user's profile name information from the People API.
//This will contain a user's names
function getCurrentUser(){
var currentuser = People.People.get("people/me", {"personFields":"names"})
return currentuser.names[0]
}
var firstname = getCurrentUser().givenName //gets the user's first name
var fullname = getCurrentUser().displayName // gets the user's full profile name
//You can then add either variable as the name
GmailApp.sendEmail(address, subject, body, {htmlBody : body signature,cc: "[email protected]",name:firstname});
In case you need it you can also retrieve much more than just the names, but also other user profile info. Check out the documentation here.
CodePudding user response:
Use
const name = 'Alex from Ban' // replace the string by someway to assign the value that you want to use.
GmailApp.sendEmail(address, subject, body, {htmlBody : body, name: name });
References