Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Cannot attach Contact as ItemAttachment to an email #75

Open
JohnMAustin78 opened this issue Apr 20, 2015 · 5 comments
Open

Cannot attach Contact as ItemAttachment to an email #75

JohnMAustin78 opened this issue Apr 20, 2015 · 5 comments

Comments

@JohnMAustin78
Copy link

Folks,
The following code raises an internal server exception. The item object in the 2nd argument of my method actually cast from a valid Contact object. The client is verified to be valid, the mail Id came from a new message I created and did not send yet. The message sits in the user's draft mail message folder.

I get the following internal server (501) error:

"Object reference not set to an instance of an object”

/**
 * Gets a message out of the user's draft folder by id and adds a text file attachment
 *
 * @param mailId  The id of the draft email that will get the attachment
 * @param itemToAttach The mail message to attach
 * @return Boolean. The result of the operation. True if success
 * @version 1.0
 */
public Boolean addItemAttachment(
        String mailId
        , Item itemToAttach) throws ExecutionException, InterruptedException {
    ItemAttachment itemAttachment = new ItemAttachment();
    itemAttachment.setName(itemToAttach.getClass().getName());
    itemAttachment.setItem(itemToAttach);
    itemAttachment.setContentType(itemToAttach.getClass().getName());
    itemAttachment.setIsInline(false);
    itemAttachment.setId(itemToAttach.getId());
    mMailClient
            .getMe()
            .getMessages()
            .getById(mailId)
            .getAttachments()
            .add(itemAttachment)
            .get();
    return true;
}
@marcote
Copy link
Contributor

marcote commented Apr 20, 2015

Hi John.
If you try to do the same thing using a REST client like Fiddler, can you reproduce the behavior?

@JohnMAustin78
Copy link
Author

Good question. I will give that a try.
From: Marcos Torres <notifications@gh.neting.ccmailto:notifications@github.com>
Reply-To: OfficeDev/Office-365-SDK-for-Android <reply@reply.gh.neting.ccmailto:reply@reply.github.com>
Date: Monday, April 20, 2015 at 9:46 AM
To: OfficeDev/Office-365-SDK-for-Android <Office-365-SDK-for-Android@noreply.gh.neting.ccmailto:Office-365-SDK-for-Android@noreply.github.com>
Cc: John Austin <johnau@microsoft.commailto:johnau@microsoft.com>
Subject: Re: [Office-365-SDK-for-Android] Cannot attach Contact as ItemAttachment to an email (#75)

Hi John.
If you try to do the same thing using a REST client like Fiddler, can you reproduce the behavior?

Reply to this email directly or view it on GitHubhttps://github.com//issues/75#issuecomment-94505256.

@JohnMAustin78
Copy link
Author

Hi Marcos,

I've tried the request using the Charles Proxy tool. I get the same error that I got in the response to the call using the client library.

Request
The following is the request JSON payload when a contact is attached:

{
"Item": {
"BusinessAddress": {
"@odata.type": "#Microsoft.OutlookServices.PhysicalAddress"
},
"BusinessPhones": [null, null],
"DisplayName": "New Contact created on 2015-23-03 at 11:46",
"EmailAddresses": [{
"Address": "AlexD@patsoldemo4.onmicrosoft.com",
"Name": "Alex Darrow",
"@odata.type": "#Microsoft.OutlookServices.EmailAddress"
},
null, null],
"FileAs": "",
"GivenName": "New Contact",
"HomeAddress": {
"@odata.type": "#Microsoft.OutlookServices.PhysicalAddress"
},
"HomePhones": [null, null],
"ImAddresses": [null, null, null],
"MobilePhone1": "5554251212",
"OtherAddress": {
"@odata.type": "#Microsoft.OutlookServices.PhysicalAddress"
},
"ParentFolderId": "AAMkADE5NTIzMjhjLWFkYjEtNDdjYS04NDBmLWMzYjNkZDM2ZDAzMAAuAAAAAACYmH-NJgoiR5Hddx6ToBrSAQA7Z34e4-q-Ta7-0CC9gFcSAAAAAAEOAAA=",
"Surname": " created on 2015-23-03 at 11:46",
"Categories": [],
"ChangeKey": "EQAAABYAAAA7Z34e4/q/Ta7/0CC9gFcSAAAKOuzn",
"DateTimeCreated": "2015-03-23T18:45:03.0000000Z",
"DateTimeLastModified": "2015-03-25T21:48:59.0000000Z",
"Id": "AAMkADE5NTIzMjhjLWFkYjEtNDdjYS04NDBmLWMzYjNkZDM2ZDAzMABGAAAAAACYmH-NJgoiR5Hddx6ToBrSBwA7Z34e4-q-Ta7-0CC9gFcSAAAAAAEOAAA7Z34e4-q-Ta7-0CC9gFcSAAAH3Go5AAA=",
"@odata.type": "#Microsoft.OutlookServices.Contact"
},
"ContentType": "com.microsoft.outlookservices.Contact",
"IsInline": false,
"Name": "com.microsoft.outlookservices.Contact",
"Id": "AAMkADE5NTIzMjhjLWFkYjEtNDdjYS04NDBmLWMzYjNkZDM2ZDAzMABGAAAAAACYmH-NJgoiR5Hddx6ToBrSBwA7Z34e4-q-Ta7-0CC9gFcSAAAAAAEOAAA7Z34e4-q-Ta7-0CC9gFcSAAAH3Go5AAA=",
"@odata.type": "#Microsoft.OutlookServices.ItemAttachment"
}

Response
{
"error": {
"code": "ErrorInternalServerError",
"message": "Object reference not set to an instance of an object."
}
}

From: Marcos Torres <notifications@gh.neting.ccmailto:notifications@github.com>
Reply-To: OfficeDev/Office-365-SDK-for-Android <reply@reply.gh.neting.ccmailto:reply@reply.github.com>
Date: Monday, April 20, 2015 at 9:46 AM
To: OfficeDev/Office-365-SDK-for-Android <Office-365-SDK-for-Android@noreply.gh.neting.ccmailto:Office-365-SDK-for-Android@noreply.github.com>
Cc: John Austin <johnau@microsoft.commailto:johnau@microsoft.com>
Subject: Re: [Office-365-SDK-for-Android] Cannot attach Contact as ItemAttachment to an email (#75)

Hi John.
If you try to do the same thing using a REST client like Fiddler, can you reproduce the behavior?

Reply to this email directly or view it on GitHubhttps://github.com//issues/75#issuecomment-94505256.

@meneja01
Copy link

I am having an issue with null references for attachments as well. Whenever I try to do a .getAttachments() on a Message object, I get null returned, despite the .getHasAttachments() flag being set to true.

@marcote
Copy link
Contributor

marcote commented Apr 21, 2015

Let me review this please. Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants