コード例 #1
0
        //DA QUI IL MIO CODICE PERSONALIZZATO

        //GENERALI

        //Codice per permettere l'avvio dell'app Posta e inviare mail
        private async void ComposeEmail(Windows.ApplicationModel.Contacts.Contact recipient,
                                        string messageBody,
                                        StorageFile attachmentFile)
        {
            var emailMessage = new Windows.ApplicationModel.Email.EmailMessage();

            emailMessage.Body = messageBody;

            if (attachmentFile != null)
            {
                var stream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(attachmentFile);

                var attachment = new Windows.ApplicationModel.Email.EmailAttachment(
                    attachmentFile.Name,
                    stream);

                emailMessage.Attachments.Add(attachment);
            }

            var email = recipient.Emails.FirstOrDefault <Windows.ApplicationModel.Contacts.ContactEmail>();

            if (email != null)
            {
                var emailRecipient = new Windows.ApplicationModel.Email.EmailRecipient(email.Address);
                emailMessage.To.Add(emailRecipient);
            }

            await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage);
        }
        public async Task PlatformComposeAsync(EmailMessage?message)
        {
            var isComposeSupported = ApiInformation.IsTypePresent("Windows.ApplicationModel.Email.EmailManager");

            if (!isComposeSupported)
            {
                throw new FeatureNotSupportedException();
            }

            if (message != null && message.BodyFormat != EmailBodyFormat.PlainText)
            {
                throw new FeatureNotSupportedException("UWP can only compose plain text email messages.");
            }

            var nativeMessage = new NativeEmailMessage();

            if (!string.IsNullOrEmpty(message?.Body))
            {
                nativeMessage.Body = message.Body;
            }
            if (!string.IsNullOrEmpty(message?.Subject))
            {
                nativeMessage.Subject = message.Subject;
            }
            Sync(message?.To, nativeMessage.To);
            Sync(message?.Cc, nativeMessage.CC);
            Sync(message?.Bcc, nativeMessage.Bcc);

            if (message?.Attachments?.Count > 0)
            {
                foreach (var attachment in message.Attachments)
                {
                    var path = NormalizePath(attachment.FullPath);
                    var file = /*attachment.File ??*/ await StorageFile.GetFileFromPathAsync(path);

                    var stream           = RandomAccessStreamReference.CreateFromFile(file);
                    var nativeAttachment = new NativeEmailAttachment(attachment.FileName, stream);

                    if (!string.IsNullOrEmpty(attachment.ContentType))
                    {
                        nativeAttachment.MimeType = attachment.ContentType;
                    }
                    else if (!string.IsNullOrWhiteSpace(file?.ContentType))
                    {
                        nativeAttachment.MimeType = file.ContentType;
                    }

                    nativeMessage.Attachments.Add(nativeAttachment);
                }
            }

            await EmailManager.ShowComposeNewEmailAsync(nativeMessage);
        }
コード例 #3
0
        private async void sendMail(StorageFile anhang)
        {
            EmailMessage emailMessage = new EmailMessage();
            emailMessage.To.Add(new EmailRecipient("*****@*****.**"));
            string messageBody = "Mailinhalt..... Text";
            emailMessage.Body = messageBody;
            emailMessage.Subject = "Testen als Betreff";

            var stream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(anhang);
            var attachment = new Windows.ApplicationModel.Email.EmailAttachment
            (
                anhang.Name,
                stream);
            emailMessage.Attachments.Add(attachment);

            await EmailManager.ShowComposeNewEmailAsync(emailMessage);
        }
コード例 #4
0
        private async void sendMail(StorageFile anhang)
        {
            EmailMessage emailMessage = new EmailMessage();

            emailMessage.To.Add(new EmailRecipient("*****@*****.**"));
            string messageBody = "Mailinhalt..... Text";

            emailMessage.Body    = messageBody;
            emailMessage.Subject = "Testen als Betreff";

            var stream     = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(anhang);
            var attachment = new Windows.ApplicationModel.Email.EmailAttachment
                             (
                anhang.Name,
                stream);

            emailMessage.Attachments.Add(attachment);

            await EmailManager.ShowComposeNewEmailAsync(emailMessage);
        }
コード例 #5
0
        static async Task DoSendEmail(EmailMessage email)
        {
            var emailMessage = new Windows.ApplicationModel.Email.EmailMessage {
                Body = email.Message
            };

            email.Attachments.Do(async(a) =>
            {
                RandomAccessStreamReference stream;
                if (a.FilePath.IsUrl())
                {
                    stream = RandomAccessStreamReference.CreateFromUri(new Uri(a.FilePath));
                }
                else
                {
                    stream = RandomAccessStreamReference.CreateFromFile(await StorageFile.GetFileFromPathAsync(a.FilePath));
                }
                var attachmentFile = new Windows.ApplicationModel.Email.EmailAttachment(a.FileName, stream);
                emailMessage.Attachments.Add(attachmentFile);
            });

            email.Recipients.Do(r => emailMessage.To.Add(new EmailRecipient(r)));
            await EmailManager.ShowComposeNewEmailAsync(emailMessage);
        }
コード例 #6
0
        private async void submitButton_Click(object sender, RoutedEventArgs e)
        {
            //MessageBox
            if (selectProblemButton.Content.ToString() == "choose a problem")
            {
                MessageDialog invalidProblem = new MessageDialog("You need to select a problem type before you can submit a ticket.", "Invalid problem type");
                await invalidProblem.ShowAsync();
            }

            else if (descriptionText.Text == "")
            {
                MessageDialog invalidDescription = new MessageDialog("You need to type a description before you can submit a ticket.", "You need to type a description");
                await invalidDescription.ShowAsync();
            }

            else if (expletiveslist.expletivesArray.Contains(descriptionText.Text))
            {
                MessageDialog expletivesDetected = new MessageDialog("There are expletives in your description. Please remove these before sending the ticket.", "Expletives detected");
                await expletivesDetected.ShowAsync();
            }

            else
            {
                //Get variables
                var submitDate   = DateTime.Now.ToString();
                var problem      = selectProblemButton.Content.ToString();
                var location     = selectRoomButton.Content.ToString();
                var attachedFile = fileText.Text.ToString();

                string videoAttached = null;
                if (attachedFile.Contains("mp4"))
                {
                    videoAttached = "Attached video: " + attachedFile;
                }

                else
                {
                    videoAttached = "Attached photo: " + attachedFile;
                }

                //WRITE
                //Create the text file to hold the data
                Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
                Windows.Storage.StorageFile   ticketsFile   = await storageFolder.CreateFileAsync("tickets.txt", Windows.Storage.CreationCollisionOption.OpenIfExists);

                await FileIO.AppendTextAsync(ticketsFile, "\n" + "Submitted: " + submitDate + "\n" + "Problem: " + problem + "\n" + "Room: " + location + "\n" + "Description: " + descriptionText.Text + "\n" + "Priority: " + priority + "\n" + videoAttached + "\n");

                //Use stream to write to the file
                var stream = await ticketsFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

                using (var outputStream = stream.GetOutputStreamAt(0))
                {
                    using (var dataWriter = new Windows.Storage.Streams.DataWriter(outputStream))
                    {
                        await dataWriter.StoreAsync();

                        await outputStream.FlushAsync();
                    }
                }
                stream.Dispose(); // Or use the stream variable (see previous code snippet) with a using statement as well.*/

                //READ
                //Open the text file
                stream = await ticketsFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

                ulong size = stream.Size;

                using (var inputStream = stream.GetInputStreamAt(0))
                {
                    using (var dataReader = new Windows.Storage.Streams.DataReader(inputStream))
                    {
                        uint numBytesLoaded = await dataReader.LoadAsync((uint)size);

                        string savedTickets = dataReader.ReadString(numBytesLoaded);

                        ticketTextBlock.Text = savedTickets;
                    }
                }
                stream.Dispose();

                //SEND EMAIL
                string messageBody  = "\n" + "Ticket submitted: " + submitDate + "\n" + "Problem: " + problem.ToUpper() + "\n" + "Room: " + location + "\n" + "Description: " + descriptionText.Text + "\n" + "Priority: " + priority + "\n" + videoAttached + "\n" + "\n" + "----------------------------------------------------------" + "\n" + "Sent from wh-at Helpdesk (for Windows 10)" + "\n" + "\n" + "You may respond to this email, it will send an email to the sender.";
                string messageTitle = problem.ToUpper() + " | " + location;

                if (_file == null)
                {
                    EmailMessage emailMessage = new EmailMessage();
                    emailMessage.To.Add(new EmailRecipient("*****@*****.**"));
                    emailMessage.Body    = messageBody;
                    emailMessage.Subject = messageTitle;
                    await EmailManager.ShowComposeNewEmailAsync(emailMessage);
                }

                else
                {
                    EmailMessage emailMessage = new EmailMessage();
                    emailMessage.To.Add(new EmailRecipient("*****@*****.**"));
                    emailMessage.Body    = messageBody;
                    emailMessage.Subject = messageTitle;

                    var emailStream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(_file);
                    var attachment  = new Windows.ApplicationModel.Email.EmailAttachment(
                        _file.Name,
                        emailStream);
                    emailMessage.Attachments.Add(attachment);

                    await EmailManager.ShowComposeNewEmailAsync(emailMessage);
                }
            }
        }
コード例 #7
0
        private async void SendButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            if (TSubject.Text == "" || (TToEmail.Text == "" && Send.IsChecked.Value))
            {
                return;
            }
            if (Send.IsChecked.Value)   // Send
            {
                try {
                    EmailMessage email = new EmailMessage();
                    email.Subject = TSubject.Text;
                    email.To.Add(new EmailRecipient(TToEmail.Text));
                    StorageFolder tempFolder = await StorageFolder.GetFolderFromPathAsync(Path.GetTempPath());

                    try {
                        await FileIO.WriteTextAsync(await tempFolder.CreateFileAsync("Report.html", CreationCollisionOption.ReplaceExisting), htmlOUT);
                    } catch (Exception exc) {
                        await new MessageDialog(exc.Message).ShowAsync();
                    }
                    StorageFile attachmentFile = await tempFolder.GetFileAsync("Report.html");

                    if (attachmentFile != null)
                    {
                        var stream     = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(attachmentFile);
                        var attachment = new Windows.ApplicationModel.Email.EmailAttachment(attachmentFile.Name, stream);
                        email.Attachments.Add(attachment);
                    }
                    await EmailManager.ShowComposeNewEmailAsync(email);

                    this.Frame.Navigate(typeof(OutputPage));
                } catch (Exception ex) {
                    await new MessageDialog(ex.Message).ShowAsync();
                    this.Frame.Navigate(typeof(OutputPage));
                }
            }
            else   //Export
            {
                var picker = new FileSavePicker();
                picker.SuggestedStartLocation = PickerLocationId.ComputerFolder;
                picker.CommitButtonText       = "Select";
                picker.SuggestedFileName      = "Report.html";
                picker.FileTypeChoices.Add("HTML File", new List <string>()
                {
                    ".html"
                });
                try {
                    StorageFile ReportFile = await picker.PickSaveFileAsync();

                    if (ReportFile != null)
                    {
                        try {
                            await Windows.Storage.FileIO.WriteTextAsync(ReportFile, htmlOUT);
                        }
                        catch (Exception exe) {
                            await new MessageDialog(exe.Message).ShowAsync();
                        }
                    }
                    else
                    {
                        await new MessageDialog("Operation Canceled").ShowAsync();
                    }
                } catch (Exception ex) {
                    await new MessageDialog("Operation Canceled : " + ex.Message + "\n\n" + " Stack Trace: " + ex.StackTrace).ShowAsync();
                }
            }
        }