locked
Sending email without Sharing Contracts

    Question

  • Hi,

    What I want to do is sending email without the Sharing Contract in a Windows Store App. 

    I am using the "mailto" protocol, but it has a limitation relating to its length as it is described here:

    http://support.microsoft.com/kb/208427/en-gb

    I have to send an email with more than 2083 characters, therefore this approach is not working fine. I don't want to use the Sharing Contract because it has limitation also. E.g. because we don't know about the target of the sharing, we are not able to fill out the details of the email like (subject, recipient, etc) only the body can be set.

    Can anybody suggest a way to send email from the device in offline mode (we cannot use any webservice to do that task), therefore I need a solution which opens the default email client on the tablet and fill out the details of the email?

    Thanks,

    Sandor

    Tuesday, February 11, 2014 9:11 AM

Answers

  • There is no direct way to communicate with other apps. The sharing contract and launching URIs are your only options to talk to a mail client (and neither are guaranteed: the user may not have a mail client configured). For your scenario I'd try uploading directly to a web service, bypassing the mail client. You can prepare the mail and save it in your own "drafts" folder, then either send it the next time the user runs the op hen connected or use a background task to upload it when networking is available.

    --Rob


    Tuesday, February 11, 2014 4:25 PM
    Moderator
  • If the tablet is offline, then how do you send email? You keep coming back to that but being offline isn't your problem in this case. Either you are online or offline. When you're offline, you have exactly the same problems that you have whether you use an email client such as Outlook or the built-in mail app, or you store email content in a local store and then connect to a webservice when your machine is online again.

    Bluntly, no, you can't do what you're asking for.  You're explicitly trying to avoid the stated methods which most devs use, and are asking for a workaround for a problem that doesn't exist in most cases.

    Webservices are the most effective method in this case.  You just connect to the webservice, *when you're online*, and send the email.

    If you are bound and determined to use a built-in email client, then you need to find ways to avoid the length limit.  One way is to pull in content from the web when the email is read, rather than embed all of it in the email itself.  That's all I can think of.

    I think we've beat this horse to death. 


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, February 12, 2014 2:01 PM
    Moderator

All replies

  • You can't send *anything* when you're offline.  
    Are you actually running into this limit with the mailto protocol, or is it hypothetical at this point?  I'm asking because that KB article refers specifically to IE.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, February 11, 2014 3:02 PM
    Moderator

  • When I said that I'd like to send email offline, I meant that I generate an email and it invokes the built in email app, so I'll have a draft from that email. Thereafter I am able to send that email when I have internet connection on the device.

    About the limitation what I mentioned it, yes, actually I met this issue when I had an email body longer than this limit.

    Tuesday, February 11, 2014 3:26 PM
  • I don't think you're going to get what you want. Can you explain more about why the mail is so long?  Maybe we can figure out an alternative.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, February 11, 2014 3:34 PM
    Moderator
  • The content of that email consists of data about a product. So we have different values for the specific properties, therefore you don't know the max length of that email body. And we have another content in that email which can be a long part e.g. conditions etc.

    So when we are creating the email body, we don't know anything from the length of it. It can be easily more than the approx 2k limit.

    Tuesday, February 11, 2014 3:39 PM
  • Is it possible for the email to be in HTML format and you pull in that data from the web?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, February 11, 2014 4:07 PM
    Moderator
  • What do you mean exactly? As I mentioned the application has to be capable to run without internet connection. 

    If I compose the email in HTML format, how can I pass this as the body to the email client?

    Tuesday, February 11, 2014 4:12 PM
  • There is no direct way to communicate with other apps. The sharing contract and launching URIs are your only options to talk to a mail client (and neither are guaranteed: the user may not have a mail client configured). For your scenario I'd try uploading directly to a web service, bypassing the mail client. You can prepare the mail and save it in your own "drafts" folder, then either send it the next time the user runs the op hen connected or use a background task to upload it when networking is available.

    --Rob


    Tuesday, February 11, 2014 4:25 PM
    Moderator
  • At some point you're going to have to be connected to the internet to send an email. If instead of placing all of the content in the body of the email itself, you may just have a link embedded to the content so that it appears in the email when it's sent, not necessarily before. That would allow you to have emails created but not exceed the length limit.

    There's also the way that Rob was suggesting, which is where I would go next.  You should have a web service that your app communicates with in order to send the data.  Of course, you may also see if there's a third-party SMTP API which you could use to send email directly when connected to the internet, so that you could have complete control over the email content.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, February 11, 2014 6:20 PM
    Moderator
  • If the tablet is offline, you cannot use any web service to communicate with.

    Isn't there any other way to fill out an email body, which length is over the limit?

    Does that mean that a windows store app cannot create email with more than approx 2000 character in its body, if you don't want to use the sharing contract?

    Wednesday, February 12, 2014 9:16 AM
  • If the tablet is offline, then how do you send email? You keep coming back to that but being offline isn't your problem in this case. Either you are online or offline. When you're offline, you have exactly the same problems that you have whether you use an email client such as Outlook or the built-in mail app, or you store email content in a local store and then connect to a webservice when your machine is online again.

    Bluntly, no, you can't do what you're asking for.  You're explicitly trying to avoid the stated methods which most devs use, and are asking for a workaround for a problem that doesn't exist in most cases.

    Webservices are the most effective method in this case.  You just connect to the webservice, *when you're online*, and send the email.

    If you are bound and determined to use a built-in email client, then you need to find ways to avoid the length limit.  One way is to pull in content from the web when the email is read, rather than embed all of it in the email itself.  That's all I can think of.

    I think we've beat this horse to death. 


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, February 12, 2014 2:01 PM
    Moderator
  • Thanks the posts lads!

    Wednesday, February 12, 2014 2:14 PM