Class User
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
內容詳盡的說明文件
getEmail()
取得使用者的電子郵件地址 (如有)。如果安全性政策不允許存取使用者的電子郵件地址,這個方法會傳回空白字串。可使用電子郵件地址的情況各有不同:舉例來說,如果使用者在未經使用者授權的情況下,允許指令碼執行,則使用者電子郵件地址就無法使用,例如簡單的 onOpen(e)
或 onEdit(e)
觸發條件、Google 試算表中的自訂函式,或是以「以我身分執行」方式部署的網頁應用程式 (也就是由開發人員而非使用者授權)。不過,如果開發人員自行執行指令碼,或是與使用者屬於相同的 Google Workspace 網域,則這些限制通常不適用。
// Log the email address of the person running the script.
Logger.log(Session.getActiveUser().getEmail());
回攻員
String
:使用者的電子郵件地址,如果安全性政策不允許存取使用者的電子郵件地址,則為空白字串。
已淘汰的方法
getUserLoginId()
已淘汰。自 2013 年 6 月 24 日起,已由 getEmail()
取代。
取得使用者的電子郵件地址。
// Log the email address of the person running the script.
Logger.log(Session.getActiveUser().getUserLoginId());
回攻員
String
:使用者的電子郵件地址。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eRepresents a user for scripting purposes, providing methods to access user information.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetEmail()\u003c/code\u003e retrieves the user's email address if permitted by security policies, returning a blank string otherwise.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetUserLoginId()\u003c/code\u003e is deprecated and replaced by \u003ccode\u003egetEmail()\u003c/code\u003e for retrieving the user's email address.\u003c/p\u003e\n"],["\u003cp\u003eAccess to the user's email address might be restricted in certain contexts due to security considerations, such as unauthorized script execution.\u003c/p\u003e\n"]]],[],null,["# Class User\n\nUser\n\nRepresentation of a user, suitable for scripting. \n\n### Methods\n\n| Method | Return type | Brief description |\n|---------------------------|-------------|----------------------------------------------|\n| [getEmail()](#getEmail()) | `String` | Gets the user's email address, if available. |\n\n### Deprecated methods\n\n| Method | Return type | Brief description |\n|---------------------------------------|-------------|--------------------------------|\n| [getUserLoginId()](#getUserLoginId()) | `String` | Gets the user's email address. |\n\nDetailed documentation\n----------------------\n\n### `get``Email()`\n\nGets the user's email address, if available. If security policies do not allow access to the\nuser's email address, this method returns a blank string. The circumstances in which the email\naddress is available vary: for example, the user's email address is not available in any\ncontext that allows a script to run without that user's authorization, like a simple `on``Open(e)` or `on``Edit(e)` trigger, a custom function in Google Sheets, or a web app\ndeployed to \"execute as me\" (that is, authorized by the developer instead of the user).\nHowever, these restrictions generally do not apply if the developer runs the script themselves\nor belongs to the same Google Workspace domain as the user.\n\n```javascript\n// Log the email address of the person running the script.\nLogger.log(Session.getActiveUser().getEmail());\n```\n\n#### Return\n\n\n`String` --- The user's email's address, or a blank string if security policies do not allow access\nto the user's email address.\n\nDeprecated methods\n------------------\n\n### `get``User``Login``Id()`\n\n\n**Deprecated.** As of June 24, 2013, replaced by [getEmail()](#getEmail()).\n\nGets the user's email address.\n\n```javascript\n// Log the email address of the person running the script.\nLogger.log(Session.getActiveUser().getUserLoginId());\n```\n\n#### Return\n\n\n`String` --- The user's email's address."]]