function myFunction() {
// Create a new document
var doc = DocumentApp.create('MyContactsList');
//loop all contacts and put them inside the document
var contacts = ContactsApp.getContacts();
for (var i=0; i<contacts.length; i++)
{
if ( contacts[i].getFullName() != '' )
{
try
{
doc.appendParagraph(contacts[i].getFullName() + ' ' +
contacts[i].getEmails()[0].getAddress() );
}
catch(e)
{
doc.appendParagraph(contacts[i].getFullName() + ' without email' );
}
}
}
// Save and close the document
doc.saveAndClose();
// Get the URL of the document
var url = doc.getUrl();
// Get the email address of the active user - that's you
var emailAddress = Session.getActiveUser().getEmail();
GmailApp.sendEmail(emailAddress,'Your contact list',
'The document filled with your contacts is here: ' + url);
}