kabayaba
kabayaba

Reputation: 204

Unable to send mail using activesync SendMail request schema. Status return 102 / 119

I'm able to get response for Provision, FolderSync, Sync, Search, ItemOperations etc with activesync but the life of me not able to SendMail.

I'm using 14.1 protocol version.

I've read somewhere that SendMail:Mime needs to be CData format. If Mime data is of text content, server will throw error 102 but with CData it throws 119. Below are xmls before encoded:

Below is without CData. Server throw 102 : InvalidWBXML.

<composemail:SendMail xmlns:composemail="ComposeMail">
    <composemail:ClientId>1294231504</composemail:ClientId>
    <composemail:SaveInSentItems/>
    <composemail:Mime>From: [email protected]
        To: [email protected]
        Subject: 123
        MIME-Version: 1.0
        Content-Type: text/plain; charset=utf-8

        This is the body text
    </composemail:Mime>
</composemail:SendMail>

Below is with cdata. Server throw 119 : MessageHasNoRecipient.

<composemail:SendMail xmlns:composemail="ComposeMail">
    <composemail:ClientId>1240110395</composemail:ClientId>
    <composemail:SaveInSentItems/>
    <composemail:Mime>
        <![CDATA[From: [email protected]
        To: [email protected]
        Subject: 123
        MIME-Version: 1.0
        Content-Type: text/plain; charset=utf-8

        This is the body text]]>
    </composemail:Mime>
</composemail:SendMail>

Do i need to base64 the mime message or is there a missing param in the xml?

The message string is as below if it helps:

String test = "From: [email protected]"
        +"\nTo: [email protected]"
        +"\nSubject: 123"
        +"\nMIME-Version: 1.0"
        +"\nContent-Type: text/plain; charset=utf-8"

        +"\n\nThis is the body text";

Node mimeNode = itemOperationsXML.createElementNS(Namespaces.composeMailNamespace,
            Xmlns.composeMailXmlns + ":Mime");
mimeNode.appendChild(itemOperationsXML.createCDATASection(test));
rootNode.appenChild(mimeNode );

Upvotes: 0

Views: 220

Answers (1)

kabayaba
kabayaba

Reputation: 204

Solved it. Somehow i encode the CDATA wrongly. For those using Activesync for android below is the code for ASWBXML.java for encoding byte integer:

private byte[] encodeMultiByteInteger(int value) {

    List<Byte> byteList = new ArrayList<>();
    while (value > 0) {
        byte addByte = (byte) (value & 0x7F);
        if (byteList.size() > 0) {
            addByte |= 0x80;
        }
        byteList.add(0, addByte);
        value >>= 7;
    }
    byte[] b = new byte[byteList.size()];
    for (int i = 0; i < byteList.size(); i++) {
        b[i] = byteList.get(i);
    }
    return b;

Upvotes: 0

Related Questions