Why does EWS api ErrorNonPrimarySmtpAddress error?










0















I have several user accounts in Office 365 tenant. Two of them are almost identical (have similar settings but different contact info and name).
I try to fetch information (such as all folders and items) in user's mailbox using GetFolder operation from EWS API that contains next body:



<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013"/>
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:PrimarySmtpAddress>Name.Surname@mydomain.onmicrosoft.com</t:PrimarySmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<GetFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<FolderShape>
<t:BaseShape>AllProperties</t:BaseShape>
<t:AdditionalProperties> </t:AdditionalProperties>
</FolderShape>
<FolderIds>
<t:DistinguishedFolderId Id="outbox"/>
</FolderIds>
</GetFolder>
</soap:Body>
</soap:Envelope>


I can successfully get info for one of these two mailboxes but when an error reply with the next body:



<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorNonPrimarySmtpAddress</faultcode>
<faultstring xml:lang="en-US">The primary SMTP address must be specified when referencing a mailbox.</faultstring>
<detail>
<e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorNonPrimarySmtpAddress</e:ResponseCode>
<e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The primary SMTP address must be specified when referencing a mailbox.</e:Message>
<t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<t:Value Name="Primary"/>
</t:MessageXml>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>


Why do I get such ErrorNonPrimarySmtpAddress error response? What can be the problem when I fetch data in the mailbox of the second user?










share|improve this question
























  • What is the request that returns that error? Are you specifying the primary SMTP address rather one of the proxy SMTP addresses?

    – Dmitry Streblechenko
    Nov 15 '18 at 14:32











  • @DmitryStreblechenko I've just updated the description and provided EWS GetFolder operation body that I use when I fetch info about folder in user mailbox.

    – Vasyl
    Nov 15 '18 at 15:40















0















I have several user accounts in Office 365 tenant. Two of them are almost identical (have similar settings but different contact info and name).
I try to fetch information (such as all folders and items) in user's mailbox using GetFolder operation from EWS API that contains next body:



<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013"/>
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:PrimarySmtpAddress>Name.Surname@mydomain.onmicrosoft.com</t:PrimarySmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<GetFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<FolderShape>
<t:BaseShape>AllProperties</t:BaseShape>
<t:AdditionalProperties> </t:AdditionalProperties>
</FolderShape>
<FolderIds>
<t:DistinguishedFolderId Id="outbox"/>
</FolderIds>
</GetFolder>
</soap:Body>
</soap:Envelope>


I can successfully get info for one of these two mailboxes but when an error reply with the next body:



<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorNonPrimarySmtpAddress</faultcode>
<faultstring xml:lang="en-US">The primary SMTP address must be specified when referencing a mailbox.</faultstring>
<detail>
<e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorNonPrimarySmtpAddress</e:ResponseCode>
<e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The primary SMTP address must be specified when referencing a mailbox.</e:Message>
<t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<t:Value Name="Primary"/>
</t:MessageXml>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>


Why do I get such ErrorNonPrimarySmtpAddress error response? What can be the problem when I fetch data in the mailbox of the second user?










share|improve this question
























  • What is the request that returns that error? Are you specifying the primary SMTP address rather one of the proxy SMTP addresses?

    – Dmitry Streblechenko
    Nov 15 '18 at 14:32











  • @DmitryStreblechenko I've just updated the description and provided EWS GetFolder operation body that I use when I fetch info about folder in user mailbox.

    – Vasyl
    Nov 15 '18 at 15:40













0












0








0








I have several user accounts in Office 365 tenant. Two of them are almost identical (have similar settings but different contact info and name).
I try to fetch information (such as all folders and items) in user's mailbox using GetFolder operation from EWS API that contains next body:



<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013"/>
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:PrimarySmtpAddress>Name.Surname@mydomain.onmicrosoft.com</t:PrimarySmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<GetFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<FolderShape>
<t:BaseShape>AllProperties</t:BaseShape>
<t:AdditionalProperties> </t:AdditionalProperties>
</FolderShape>
<FolderIds>
<t:DistinguishedFolderId Id="outbox"/>
</FolderIds>
</GetFolder>
</soap:Body>
</soap:Envelope>


I can successfully get info for one of these two mailboxes but when an error reply with the next body:



<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorNonPrimarySmtpAddress</faultcode>
<faultstring xml:lang="en-US">The primary SMTP address must be specified when referencing a mailbox.</faultstring>
<detail>
<e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorNonPrimarySmtpAddress</e:ResponseCode>
<e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The primary SMTP address must be specified when referencing a mailbox.</e:Message>
<t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<t:Value Name="Primary"/>
</t:MessageXml>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>


Why do I get such ErrorNonPrimarySmtpAddress error response? What can be the problem when I fetch data in the mailbox of the second user?










share|improve this question
















I have several user accounts in Office 365 tenant. Two of them are almost identical (have similar settings but different contact info and name).
I try to fetch information (such as all folders and items) in user's mailbox using GetFolder operation from EWS API that contains next body:



<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013"/>
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:PrimarySmtpAddress>Name.Surname@mydomain.onmicrosoft.com</t:PrimarySmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<GetFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<FolderShape>
<t:BaseShape>AllProperties</t:BaseShape>
<t:AdditionalProperties> </t:AdditionalProperties>
</FolderShape>
<FolderIds>
<t:DistinguishedFolderId Id="outbox"/>
</FolderIds>
</GetFolder>
</soap:Body>
</soap:Envelope>


I can successfully get info for one of these two mailboxes but when an error reply with the next body:



<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorNonPrimarySmtpAddress</faultcode>
<faultstring xml:lang="en-US">The primary SMTP address must be specified when referencing a mailbox.</faultstring>
<detail>
<e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorNonPrimarySmtpAddress</e:ResponseCode>
<e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The primary SMTP address must be specified when referencing a mailbox.</e:Message>
<t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<t:Value Name="Primary"/>
</t:MessageXml>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>


Why do I get such ErrorNonPrimarySmtpAddress error response? What can be the problem when I fetch data in the mailbox of the second user?







outlook office365 exchangewebservices






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 14:59







Vasyl

















asked Nov 15 '18 at 14:25









VasylVasyl

7419




7419












  • What is the request that returns that error? Are you specifying the primary SMTP address rather one of the proxy SMTP addresses?

    – Dmitry Streblechenko
    Nov 15 '18 at 14:32











  • @DmitryStreblechenko I've just updated the description and provided EWS GetFolder operation body that I use when I fetch info about folder in user mailbox.

    – Vasyl
    Nov 15 '18 at 15:40

















  • What is the request that returns that error? Are you specifying the primary SMTP address rather one of the proxy SMTP addresses?

    – Dmitry Streblechenko
    Nov 15 '18 at 14:32











  • @DmitryStreblechenko I've just updated the description and provided EWS GetFolder operation body that I use when I fetch info about folder in user mailbox.

    – Vasyl
    Nov 15 '18 at 15:40
















What is the request that returns that error? Are you specifying the primary SMTP address rather one of the proxy SMTP addresses?

– Dmitry Streblechenko
Nov 15 '18 at 14:32





What is the request that returns that error? Are you specifying the primary SMTP address rather one of the proxy SMTP addresses?

– Dmitry Streblechenko
Nov 15 '18 at 14:32













@DmitryStreblechenko I've just updated the description and provided EWS GetFolder operation body that I use when I fetch info about folder in user mailbox.

– Vasyl
Nov 15 '18 at 15:40





@DmitryStreblechenko I've just updated the description and provided EWS GetFolder operation body that I use when I fetch info about folder in user mailbox.

– Vasyl
Nov 15 '18 at 15:40












1 Answer
1






active

oldest

votes


















0














You need to use the primary SMTP address - I doubt Name.Surname@mydomain.onmicrosoft.com is the primary address.



Open the address book in Outlook (Ctrl+Shift+B), open the user, switch to the "E-mail Addresses" tab, look for the address with the "SMTP:" prefix (note the caps).






share|improve this answer























  • you probably suggest using Outlook desktop client but I don't use it. How can I find this in Office 365 Online? And why Name.Surname@mydomain.onmicrosoft.com can't be a primary address?

    – Vasyl
    Nov 16 '18 at 8:15











  • It can be, but most likely it is not - no sane company would expose something like mycompany.onmicrosoft.com instead of mycompany.com to the outside world.

    – Dmitry Streblechenko
    Nov 16 '18 at 14:54











  • When you send an email from that account to an external address (e.,g. Yahoo or Gmail), what is the SMTP address associated with the sender? That woudl be the primary SMTP address.

    – Dmitry Streblechenko
    Nov 16 '18 at 14:55











  • Actually I only know the mail of every user in the same form: Name.Surname@mydomain.onmicrosoft.com And I can see this in Office 365 "Microsoft 365 admin center" under the "Users" tab as well.

    – Vasyl
    Nov 16 '18 at 15:14











  • When you edit the user's email addresses, on top of the screen you will see the current default email address - "Primary email address and username"

    – Dmitry Streblechenko
    Nov 16 '18 at 15:20










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321581%2fwhy-does-ews-api-errornonprimarysmtpaddress-error%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You need to use the primary SMTP address - I doubt Name.Surname@mydomain.onmicrosoft.com is the primary address.



Open the address book in Outlook (Ctrl+Shift+B), open the user, switch to the "E-mail Addresses" tab, look for the address with the "SMTP:" prefix (note the caps).






share|improve this answer























  • you probably suggest using Outlook desktop client but I don't use it. How can I find this in Office 365 Online? And why Name.Surname@mydomain.onmicrosoft.com can't be a primary address?

    – Vasyl
    Nov 16 '18 at 8:15











  • It can be, but most likely it is not - no sane company would expose something like mycompany.onmicrosoft.com instead of mycompany.com to the outside world.

    – Dmitry Streblechenko
    Nov 16 '18 at 14:54











  • When you send an email from that account to an external address (e.,g. Yahoo or Gmail), what is the SMTP address associated with the sender? That woudl be the primary SMTP address.

    – Dmitry Streblechenko
    Nov 16 '18 at 14:55











  • Actually I only know the mail of every user in the same form: Name.Surname@mydomain.onmicrosoft.com And I can see this in Office 365 "Microsoft 365 admin center" under the "Users" tab as well.

    – Vasyl
    Nov 16 '18 at 15:14











  • When you edit the user's email addresses, on top of the screen you will see the current default email address - "Primary email address and username"

    – Dmitry Streblechenko
    Nov 16 '18 at 15:20















0














You need to use the primary SMTP address - I doubt Name.Surname@mydomain.onmicrosoft.com is the primary address.



Open the address book in Outlook (Ctrl+Shift+B), open the user, switch to the "E-mail Addresses" tab, look for the address with the "SMTP:" prefix (note the caps).






share|improve this answer























  • you probably suggest using Outlook desktop client but I don't use it. How can I find this in Office 365 Online? And why Name.Surname@mydomain.onmicrosoft.com can't be a primary address?

    – Vasyl
    Nov 16 '18 at 8:15











  • It can be, but most likely it is not - no sane company would expose something like mycompany.onmicrosoft.com instead of mycompany.com to the outside world.

    – Dmitry Streblechenko
    Nov 16 '18 at 14:54











  • When you send an email from that account to an external address (e.,g. Yahoo or Gmail), what is the SMTP address associated with the sender? That woudl be the primary SMTP address.

    – Dmitry Streblechenko
    Nov 16 '18 at 14:55











  • Actually I only know the mail of every user in the same form: Name.Surname@mydomain.onmicrosoft.com And I can see this in Office 365 "Microsoft 365 admin center" under the "Users" tab as well.

    – Vasyl
    Nov 16 '18 at 15:14











  • When you edit the user's email addresses, on top of the screen you will see the current default email address - "Primary email address and username"

    – Dmitry Streblechenko
    Nov 16 '18 at 15:20













0












0








0







You need to use the primary SMTP address - I doubt Name.Surname@mydomain.onmicrosoft.com is the primary address.



Open the address book in Outlook (Ctrl+Shift+B), open the user, switch to the "E-mail Addresses" tab, look for the address with the "SMTP:" prefix (note the caps).






share|improve this answer













You need to use the primary SMTP address - I doubt Name.Surname@mydomain.onmicrosoft.com is the primary address.



Open the address book in Outlook (Ctrl+Shift+B), open the user, switch to the "E-mail Addresses" tab, look for the address with the "SMTP:" prefix (note the caps).







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 15:44









Dmitry StreblechenkoDmitry Streblechenko

44.2k32860




44.2k32860












  • you probably suggest using Outlook desktop client but I don't use it. How can I find this in Office 365 Online? And why Name.Surname@mydomain.onmicrosoft.com can't be a primary address?

    – Vasyl
    Nov 16 '18 at 8:15











  • It can be, but most likely it is not - no sane company would expose something like mycompany.onmicrosoft.com instead of mycompany.com to the outside world.

    – Dmitry Streblechenko
    Nov 16 '18 at 14:54











  • When you send an email from that account to an external address (e.,g. Yahoo or Gmail), what is the SMTP address associated with the sender? That woudl be the primary SMTP address.

    – Dmitry Streblechenko
    Nov 16 '18 at 14:55











  • Actually I only know the mail of every user in the same form: Name.Surname@mydomain.onmicrosoft.com And I can see this in Office 365 "Microsoft 365 admin center" under the "Users" tab as well.

    – Vasyl
    Nov 16 '18 at 15:14











  • When you edit the user's email addresses, on top of the screen you will see the current default email address - "Primary email address and username"

    – Dmitry Streblechenko
    Nov 16 '18 at 15:20

















  • you probably suggest using Outlook desktop client but I don't use it. How can I find this in Office 365 Online? And why Name.Surname@mydomain.onmicrosoft.com can't be a primary address?

    – Vasyl
    Nov 16 '18 at 8:15











  • It can be, but most likely it is not - no sane company would expose something like mycompany.onmicrosoft.com instead of mycompany.com to the outside world.

    – Dmitry Streblechenko
    Nov 16 '18 at 14:54











  • When you send an email from that account to an external address (e.,g. Yahoo or Gmail), what is the SMTP address associated with the sender? That woudl be the primary SMTP address.

    – Dmitry Streblechenko
    Nov 16 '18 at 14:55











  • Actually I only know the mail of every user in the same form: Name.Surname@mydomain.onmicrosoft.com And I can see this in Office 365 "Microsoft 365 admin center" under the "Users" tab as well.

    – Vasyl
    Nov 16 '18 at 15:14











  • When you edit the user's email addresses, on top of the screen you will see the current default email address - "Primary email address and username"

    – Dmitry Streblechenko
    Nov 16 '18 at 15:20
















you probably suggest using Outlook desktop client but I don't use it. How can I find this in Office 365 Online? And why Name.Surname@mydomain.onmicrosoft.com can't be a primary address?

– Vasyl
Nov 16 '18 at 8:15





you probably suggest using Outlook desktop client but I don't use it. How can I find this in Office 365 Online? And why Name.Surname@mydomain.onmicrosoft.com can't be a primary address?

– Vasyl
Nov 16 '18 at 8:15













It can be, but most likely it is not - no sane company would expose something like mycompany.onmicrosoft.com instead of mycompany.com to the outside world.

– Dmitry Streblechenko
Nov 16 '18 at 14:54





It can be, but most likely it is not - no sane company would expose something like mycompany.onmicrosoft.com instead of mycompany.com to the outside world.

– Dmitry Streblechenko
Nov 16 '18 at 14:54













When you send an email from that account to an external address (e.,g. Yahoo or Gmail), what is the SMTP address associated with the sender? That woudl be the primary SMTP address.

– Dmitry Streblechenko
Nov 16 '18 at 14:55





When you send an email from that account to an external address (e.,g. Yahoo or Gmail), what is the SMTP address associated with the sender? That woudl be the primary SMTP address.

– Dmitry Streblechenko
Nov 16 '18 at 14:55













Actually I only know the mail of every user in the same form: Name.Surname@mydomain.onmicrosoft.com And I can see this in Office 365 "Microsoft 365 admin center" under the "Users" tab as well.

– Vasyl
Nov 16 '18 at 15:14





Actually I only know the mail of every user in the same form: Name.Surname@mydomain.onmicrosoft.com And I can see this in Office 365 "Microsoft 365 admin center" under the "Users" tab as well.

– Vasyl
Nov 16 '18 at 15:14













When you edit the user's email addresses, on top of the screen you will see the current default email address - "Primary email address and username"

– Dmitry Streblechenko
Nov 16 '18 at 15:20





When you edit the user's email addresses, on top of the screen you will see the current default email address - "Primary email address and username"

– Dmitry Streblechenko
Nov 16 '18 at 15:20



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321581%2fwhy-does-ews-api-errornonprimarysmtpaddress-error%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto