sendInvitations Method

Gg276505.note(en-us,MSDN.10).gifNote:
Current information about Live Connect is now available in the Windows Live Developer Center. The information in the following sections is provided for legacy purposes only.

Sends email messages to a list of Windows Live users.

Script:  http://js.live.net/4.1/loader.js
Feature:  Microsoft.Live.Services
Namespace:  Microsoft.Live.Services
 

instance.sendInvitations(emailInvitations, callback);

Parameters

emailInvitations
Type: array< EmailInvitation >[]()[]

The array of objects of type EmailInvitation to send.

callback
Type: SendEmailCompleted

The event handler that is invoked when the send operation is completes.

Implements

IDataContextsendInvitations(array<EmailInvitation>[]()[], SendEmailCompleted)

The sendInvitations methods can be used to send invitation messages to multiple contacts. If there is just one message, the messages parameter array contains only one EmailInvitation object. To create an email invitation, use the Microsoft.Live.$create_EmailInvitation global shortcut, which takes the same parameters as the EmailInvitation class.

Each contact in an EmailInvitation is identified by its CID. You can also send an email to a contact by using the Microsoft.Live.Services.Contact.sendInvitation method of the Contact class.

To send invitations to contacts, a user must consent and sign in to a web application.

The following code example demonstrates how to use the sendInvitation method to send an invitation email to a selected contact from a web application.

The declarative markup for the example is shown first followed by the JavaScript code. A contact list control is used to simplify the selection of a contact. Be sure to have the correct scopes specified: messenger_SignIn and wl_Contacts_View.

            <wl:signin onsignin="onSignedInCallback"></wl:signin>
            <wl:contact-list onselected="onContactSelectedCallback">
            </wl:contact-list>
            <span id="Output"></span>
             <input id="SendButton" type="button" onclick="sendMail()" value="Invite This Contact" style="visibility:hidden"; />

When a contact is selected, a function is invoked that gets the CID of the selected user and then presents a button for sending email. The following example shows the JavaScript code that supports the declarative markup.

var dataContext;
var messengerContext;
var emailToUserCid;
var infoTemplate = "First Name : {0} <br/>" +
                    "Last Name : {1} <br/>";
// Called when the send email button is clicked.
function sendMail() {
    var sendFromEmail = "test@contoso.com";
    var subject = "test email " + new Date();
    var body = "test body";
    var recipientCIDs = [Microsoft.Live.Cid.toHex(emailToUserCid)];
    var invitation = Microsoft.Live.$create_EmailInvitation(sendFromEmail, subject, body, recipientCIDs);
    var invitations = [invitation];
    dataContext.sendInvitations(invitations, function (sendEmailCompletedEventArgs) {
        var failed = sendEmailCompletedEventArgs.get_failed();
        if (sendEmailCompletedEventArgs.get_resultCode() === Microsoft.Live.AsyncResultCode.failure) {
            alert("Failed to send " + failed.length + " emails.");
            return;
        }
        else {
            alert("Email(s) sent.");
        }
    });
}
function onSignedInCallback(signInCompletedEventArgs) {
    if (signInCompletedEventArgs.get_resultCode() !== Microsoft.Live.AsyncResultCode.success) {
        alert("Failed to sign in: " + signInCompletedEventArgs.get_resultCode());
        return;
    }
    messengerContext = Microsoft.Live.App.get_messengerContext();
    dataContext = Microsoft.Live.App.get_dataContext();
}
// Called when a contact is selected.
function onContactSelectedCallback(contactSelectedEventArgs) {
    emailToUserCid = contactSelectedEventArgs.get_contact().get_cid();
    var contact = messengerContext.findContact(emailToUserCid);
    $get('Output').innerHTML = String.format(infoTemplate, contact.get_firstName(), contact.get_lastName());
    $get('SendButton').style['visibility'] = 'visible'
}

The following code example is similar to the previous example, except that the mail invitation is built using JavaScript Object Notation (JSON).

function sendMailJSON() {
    var invite = {
            "To": [Microsoft.Live.Cid.toHex(emailToUserCid)],
            "From": "test@contoso.com",
            "Subject": "test email json " + new Date(),
            "Body": "test body"
    };
    dataContext.sendInvitations([invite], function (sendEmailCompletedEventArgs) {
        var failed = sendEmailCompletedEventArgs.get_failed();
        if (sendEmailCompletedEventArgs.get_resultCode() === Microsoft.Live.AsyncResultCode.failure) {
            alert("Failed to send " + failed.length + " emails.");
            return;
        }
        else {
            alert("Email(s) sent.");
        }
    });
}

Windows Live Messenger Connect

Supported in: 4.1

Internet Explorer 8.0, Internet Explorer 7.0, Internet Explorer 6.0, Firefox 3.6, Firefox 3.5, Firefox 3.0, Firefox 2.0, Firefox 1.5, Chrome 4.0, Chrome 3.0, Chrome 2.0, Chrome 1.0, Safari 4.0, Safari 3.0

Show: