sendInvitations Method

Gg262271.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 Windows Live users.

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

instance.sendInvitations(messages, callback);

Parameters

messages
Type: array< Microsoft.Live..::.EmailInvitation >[]()[]

A list of EmailInvitation objects to send.

callback
Type: Microsoft.Live..::.SendEmailCompleted

The handler to call when the send operation is complete.

The sendInvitations method send one or more messages (invitations) to multiple contacts. If there is one message, the messages parameter array contains only one EmailInvitation instance. To create an email invitation, use the Microsoft.Live.$create_EmailInvitation convenience method, which takes the same parameters as the EmailInvitation constructor.

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

A user must consent and sign in to a web application in order to send invitations to contacts in the user's contact list.

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 JavaScript is shown first, followed by the JavaScript. A contact list control is used to simplify picking a contact. Be sure to specify the correct scopes: 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 to get the CID of the selected user and present a button for sending email. The following code shows the JavaScript 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 the mail invitation is built by using 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: