简体   繁体   English

WP8中的EmailComposeTask问题

[英]EmailComposeTask issue in WP8

I am working on a scenario where i need to send logs that i save in isolated storage file to an email from the button click event of a wp8 app. 我正在研究一种情况,我需要将wp8应用程序的按钮单击事件中保存在隔离存储文件中的日志发送到电子邮件中。 Here's how i intend to do it, 这是我打算做的事情,

        private void BtnGetLogs_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                var isoStore = IsolatedStorageFile.GetUserStoreForApplication();

                //Check if the isolated file exists
                if (isoStore.FileExists(LogFileName))
                {
                    Debug.WriteLine("The file exists!");

                    // Open the filestream to read the file
                    var isoStream = new IsolatedStorageFileStream(LogFileName, FileMode.Open, isoStore);

                    var reader = new StreamReader(isoStream);
                    string text = reader.ReadToEnd();
                    SendLogsToEmail(text.Substring(length));
         }

This is the function where i am sending an email, 这是我发送电子邮件的功能,

        private void SendLogsToEmail(string body)
        {

            var emailComposeTask = new EmailComposeTask();
            {
                emailComposeTask.Subject = "Log file to mail";

                emailComposeTask.Body = body;

                emailComposeTask.To = "sample@gmail.com";
            };

            emailComposeTask.Show();
        }

I would like to give a background on this issue as well. 我也想提供有关此问题的背景。 This is purely a windows phone 8.0 project so i wont be able to send any attachments. 这纯粹是Windows Phone 8.0项目,因此我将无法发送任何附件。 That is the reason i am trying to read all the file contents and send it over the mail. 这就是我尝试读取所有文件内容并通过邮件发送它的原因。 Please note that this is work around solution for something i am working on. 请注意,这是我正在解决的解决方案。 This is an edge case scenario where i am not able to fetch logs from IsoStoreSpy or any other tools because of OEM security issues. 这是一个极端情况,由于OEM安全问题,我无法从IsoStoreSpy或任何其他工具获取日志。 So in the app itself i have a button click event which reads the isolated storage file and sends a mail to the specified user. 因此,在应用程序本身中,我有一个按钮单击事件,该事件读取隔离的存储文件并将邮件发送给指定的用户。

Here's the problem, I get an ArgumentOutOfRangeException at emailComposeTask.Show(); 这是问题所在,我在emailComposeTask.Show();处收到ArgumentOutOfRangeException emailComposeTask.Show(); and the error message is, 错误消息是

Specified argument was out of the range of valid values.
Parameter name: The size of input should not exceed 64K.

The log file is a pretty big file actually. 日志文件实际上是一个很大的文件。 Is there an elegant solution to this problem? 有解决这个问题的优雅方法吗?

The error is self explaining here, your are trying to set the email body to a text that is too long. 错误是在这里自我解释,您正在尝试将电子邮件正文设置为太长的文本。

You better upload the logs somewhere like OneDrive. 您最好将日志上传到OneDrive之类的位置。

I encountered the same issue with my NZ Topo Map app when emailing tracks as kml or gpx files. 在以kml或gpx文件的形式通过电子邮件发送轨道时,我的NZ Topo Map应用程序遇到了相同的问题。 My solution was to create a simple online service that I first posted the file to via http. 我的解决方案是创建一个简单的在线服务,然后我首先通过http将文件发布到该服务。 This service would store the file in an online location for me, then send the url to the file as a response back. 此服务会将文件存储在我的在线位置,然后将URL发送给文件作为响应。 I would then include a link to the file in the email rather than attaching the file. 然后,我将在电子邮件中包含指向文件的链接,而不是附加文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM