Class EmailField

电子邮件字段

已弃用。请改用 People API 高级服务

联系人中的电子邮件字段。

方法

方法返回类型简介
getAddress()String获取此字段的地址。
getLabel()Object获取此字段的标签。
isPrimary()Boolean获取这是主字段值的确切信息。
setAddress(address)EmailField设置此字段的地址。
setAsPrimary()EmailField将此字段设置为主要字段。
setLabel(field)EmailField设置此字段的标签。
setLabel(label)EmailField设置此字段的标签。
方法返回类型简介
deleteEmailField()void从联系人中删除此电子邮件地址。
getDisplayName()String返回此电子邮件地址的显示名称。
setDisplayName(name)EmailField设置此电子邮件地址的显示名称。

详细文档

getAddress()

获取此字段的地址。

// Logs the address for the 'Home Address' field for contact 'John Doe'.
// Can be used similarly for other fields that contain addresses.
const contacts = ContactsApp.getContactsByName('John Doe');
const homeAddress = contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);
Logger.log(homeAddress[0].getAddress());

返回

String - 地址(字符串)

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

getLabel()

获取此字段的标签。这可以是 Field、ExtendedField 或 String。

// Logs the label for all the address fields associated with contact
// 'John Doe'. This method can be similarly called for any field that has
// a label.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
for (let i = 0; i < addressFields.length; i++) {
  Logger.log(addressFields[i].getLabel());
}

返回

Object - 此字段的标签

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

isPrimary()

获取这是主字段值的标志。

// Logs whether or not the first address field associated with contact
// 'John Doe' is labeled as primary. This method can be similarly called
// for any field.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
Logger.log(addressFields[0].isPrimary());

返回

Boolean - 是否为主

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

setAddress(address)

设置此字段的地址。

// Sets the address for the 'Home Address' field for contact 'John Doe'.
// Can be used similarly for other fields that contain addresses.
const contacts = ContactsApp.getContactsByName('John Doe');
const homeAddress = contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);
homeAddress[0].setAddress('123 Main St, Raleigh, NC, 27601');

参数

名称类型说明
addressString新地址

返回

EmailField - this 字段,适用于链式调用

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

setAsPrimary()

将此字段设置为主要字段。

// Sets the first address field associated with contact 'John Doe'
// as primary. This method can be similarly called for any field.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
addressFields[0].setAsPrimary();

返回

EmailField - 用于链式调用的 this FieldValue

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

setLabel(field)

设置此字段的标签。

// Sets the label to 'Work' for the first address field associated
// with contact 'John Doe'. This method can be similarly called for any
// field that has a label.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
addressFields[0].setLabel(ContactsApp.Field.WORK_ADDRESS);

参数

名称类型说明
fieldField新标准标签

返回

EmailField - 用于链式调用的 this FieldValue

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

setLabel(label)

设置此字段的标签。

// Sets the label to 'Apartment' for the first address field associated
// with contact 'John Doe'. This method can be similarly called for any
// field that has a label.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
addressFields[0].setLabel('Apartment');

参数

名称类型说明
labelString此字段的新标签

返回

EmailField - this 字段,适用于链式调用

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

已弃用的方法

已弃用。此函数已废弃,不应在新脚本中使用。

从联系人中删除此电子邮件地址。

// Retrieves and deletes the work email address for contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const workEmail = contacts[0].getEmails(ContactsApp.Field.WORK_EMAIL);
workEmail[0].deleteEmailField();

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

已弃用。此函数已废弃,不应在新脚本中使用。

返回此电子邮件地址的显示名称。

// Logs the display name for the work email address for contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const workEmail = contacts[0].getEmails(ContactsApp.Field.WORK_EMAIL);
Logger.log(workEmail[0].getDisplayName());

返回

String - 此电子邮件的显示名称

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

已弃用。此函数已废弃,不应在新脚本中使用。

设置此电子邮件地址的显示名称。

// Sets the display name to 'Doe, John' for the work email address for contact
// 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const workEmail = contacts[0].getEmails(ContactsApp.Field.WORK_EMAIL);
workEmail[0].setDisplayName('Doe, John');

参数

名称类型说明
nameString此电子邮件地址的新显示名称

返回

EmailField - 此电子邮件字段,适合用于串联

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds