Class EmailField

  • EmailField is deprecated and the People API advanced service should be used instead.

  • Represents an email field within a Contact, offering methods to manage its address, label, and primary status.

  • Provides methods like getAddress(), setLabel(), and isPrimary() to interact with email field properties.

  • Includes deprecated methods such as deleteEmailField(), getDisplayName(), and setDisplayName() which should be avoided in new scripts.

EmailField

Deprecated. Instead, use the People API advanced service

An email field in a Contact.

Methods

MethodReturn typeBrief description
getAddress() StringGet the address for this field.
getLabel() ObjectGets the label for this field.
isPrimary() BooleanGets whether this is the primary field value.
setAddress(address) (削除) EmailField (削除ここまで)Sets the address of this field.
setAsPrimary() (削除) EmailField (削除ここまで)Sets this field to primary.
setLabel(field) (削除) EmailField (削除ここまで)Sets the label of this field.
setLabel(label) (削除) EmailField (削除ここまで)Sets the label of this field.

Deprecated methods

MethodReturn typeBrief description
(削除) deleteEmailField() (削除ここまで)voidDeletes this email address from the Contact.
(削除) getDisplayName() (削除ここまで)StringReturns the display name for this email address.
(削除) setDisplayName(name) (削除ここまで)(削除) EmailField (削除ここまで)Sets the display name for this email address.

Detailed documentation

getAddress()

Get the address for this field.

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

Return

String — the address as a string

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

getLabel()

Gets the label for this field. This may be a Field, ExtendedField, or a 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.
constcontacts=ContactsApp.getContactsByName('John Doe');
constaddressFields=contacts[0].getAddresses();
for(leti=0;i < addressFields.length;i++){
Logger.log(addressFields[i].getLabel());
}

Return

Object — the label for this field

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

isPrimary()

Gets whether this is the primary field value.

// 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.
constcontacts=ContactsApp.getContactsByName('John Doe');
constaddressFields=contacts[0].getAddresses();
Logger.log(addressFields[0].isPrimary());

Return

Boolean — whether this is primary

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

setAddress(address)

Sets the address of this field.

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

Parameters

NameTypeDescription
addressStringthe new address

Return

(削除) EmailField (削除ここまで) — this field, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

setAsPrimary()

Sets this field to primary.

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

Return

(削除) EmailField (削除ここまで) — this FieldValue for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

setLabel(field)

Sets the label of this 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.
constcontacts=ContactsApp.getContactsByName('John Doe');
constaddressFields=contacts[0].getAddresses();
addressFields[0].setLabel(ContactsApp.Field.WORK_ADDRESS);

Parameters

NameTypeDescription
field(削除) Field (削除ここまで)the new standard label

Return

(削除) EmailField (削除ここまで) — this FieldValue for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

setLabel(label)

Sets the label of this field.

// 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.
constcontacts=ContactsApp.getContactsByName('John Doe');
constaddressFields=contacts[0].getAddresses();
addressFields[0].setLabel('Apartment');

Parameters

NameTypeDescription
labelStringthe new label for this field

Return

(削除) EmailField (削除ここまで) — this field, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

Deprecated methods

(削除) deleteEmailField() (削除ここまで)

Deprecated. This function is deprecated and should not be used in new scripts.

Deletes this email address from the Contact.

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

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

(削除) getDisplayName() (削除ここまで)

Deprecated. This function is deprecated and should not be used in new scripts.

Returns the display name for this email address.

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

Return

String — the display name for this email

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

(削除) setDisplayName(name) (削除ここまで)

Deprecated. This function is deprecated and should not be used in new scripts.

Sets the display name for this email address.

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

Parameters

NameTypeDescription
nameStringthe new display name for this email address

Return

(削除) EmailField (削除ここまで) — this email field, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024年12月02日 UTC.