Google Script How do I getGivenName() of getActiveUser()

前端 未结 5 2133
刺人心
刺人心 2021-01-03 02:42

Each user on the domain initiates a simple script we run for leave entitlements but we want the welcome message to be \"Hi First Name,\" however the script doesn\'t seem to

5条回答
  •  青春惊慌失措
    2021-01-03 02:51

    Another potential way of getting the display name on a gmail account is to find a Draft email in the GmailApp, and get the From header, which may have the full name. Some drafts might be setup with no display name in gmail, in which case the From header will only be the email address, but typically the From header is in the format: Firstname Lastname

    This code should get you the string above from the first gmail Draft: (note this will probably throw an exception if there are no drafts, so check that first.)

    GmailApp.getDrafts()[0].getMessage().getHeader("From")
    

    Ref: https://developers.google.com/apps-script/reference/gmail/gmail-message#getHeader(String)

    Ref: https://www.ietf.org/rfc/rfc2822.txt

提交回复
热议问题