public static async Task <bool> ComposeEmailAsync(Windows.ApplicationModel.Contacts.Contact recipient, string subject, string messageBody, string filename, byte[] fileContent) { var emailMessage = new Windows.ApplicationModel.Email.EmailMessage(); emailMessage.Subject = subject; emailMessage.Body = messageBody; if (fileContent != null) { StorageFile newFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("tempfile", CreationCollisionOption.ReplaceExisting); await Windows.Storage.FileIO.WriteBytesAsync(newFile, fileContent); var attachment = new Windows.ApplicationModel.Email.EmailAttachment( filename, newFile); emailMessage.Attachments.Add(attachment); } if (recipient != null) { 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); return(true); }
private async void Share(object sender, RoutedEventArgs e) { var emailMessage = new Windows.ApplicationModel.Email.EmailMessage(); emailMessage.Subject = listItemViewModels.select_item.title; emailMessage.Body = "due time: " + listItemViewModels.select_item.date + "\n" + "description: " + listItemViewModels.select_item.detail + "\n\n"; string[] parts = listItemViewModels.select_item.image_uri.Split('/'); string fileName = parts[parts.Length - 1]; StorageFolder folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync( "Picture", CreationCollisionOption.OpenIfExists); var attachmentFile = await folder.GetFileAsync(fileName); var stream = RandomAccessStreamReference.CreateFromFile(attachmentFile); var attachment = new Windows.ApplicationModel.Email.EmailAttachment( attachmentFile.Name, stream); emailMessage.Attachments.Add(attachment); await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage); }
private async Task 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 void Communicate(Contact kontakt) { //Email Message Objekat var emailMessage = new Windows.ApplicationModel.Email.EmailMessage(); //tekst poruke emailMessage.Body = textPoruke; StorageFile attachmentFile = null; //ako neko hoce da doda attachment na poruku moze ucitati file i proslijediti ga ovako //ovo se nikad nece pozvati, samo kao primjer kako se attachment doda 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); } //prvi mail koji se nadje var email = kontakt.Emails.FirstOrDefault<ContactEmail>(); if (email != null) { //postaviti kao recipient var emailRecipient = new Windows.ApplicationModel.Email.EmailRecipient(email.Address); //lista, moze se dodati vise kontakata emailMessage.To.Add(emailRecipient); } //poziva napokon api sa spremnom template porukom. Korisnik je naknadno moze izmjeniti koristeci mail client await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage); }
private async void exportData_Click(object sender, RoutedEventArgs e) { Windows.ApplicationModel.Email.EmailMessage emailMessage = new Windows.ApplicationModel.Email.EmailMessage(); emailMessage.To.Add(new Windows.ApplicationModel.Email.EmailRecipient("*****@*****.**")); string messageBody = "Exported DATA - accelerometer"; emailMessage.Body = messageBody; string DataFile = @"Assets\storage.txt"; Windows.Storage.StorageFolder storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; Windows.Storage.StorageFile attachmentFile = await storageFolder.GetFileAsync(DataFile); 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); } await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage); /* * IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication(); * //create new file * using (StreamWriter SW = new StreamWriter(new IsolatedStorageFileStream("Info.txt", FileMode.Create, FileAccess.Write, ISF))) * { * string text = "Hi this is the text which will be written to the file and we can retrieve that later"; * SW.WriteLine(text); * SW.Close(); * MessageBox.Show("text has been saved successfully to the file"); * } * * StorageFolder newFolder = KnownFolders.DocumentsLibrary; * StorageFile file = await newFolder.CreateFileAsync("export.txt", CreationCollisionOption.ReplaceExisting); * * string ReadedData = await FileIO.ReadTextAsync(file); * await FileIO.WriteTextAsync(file,ReadedData); */ /* * FileSavePicker savePicker = new FileSavePicker(); * * savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; * savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" }); * savePicker.SuggestedFileName = "export_accelerometer"; * * Windows.Storage.StorageFile file = await savePicker.PickSaveFileAndContinue(); * if (file != null) * { * string DataFile = @"Assets\storage.txt"; * Windows.Storage.StorageFolder storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; * Windows.Storage.StorageFile sampleFile = await storageFolder.GetFileAsync(DataFile); * Windows.Storage.CachedFileManager.DeferUpdates(sampleFile); * await Windows.Storage.FileIO.WriteTextAsync(sampleFile, sampleFile.Name); * Windows.Storage.Provider.FileUpdateStatus status = * await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(sampleFile); * } */ }
public async static Task SendEmail(string emailAddress = null, string subject = null, string messageBody = null, List <StorageFile> attachmentFiles = null) { Windows.ApplicationModel.Email.EmailMessage emailMessage = new Windows.ApplicationModel.Email.EmailMessage(); if (emailAddress != null) { emailMessage.To.Add(new Windows.ApplicationModel.Email.EmailRecipient(emailAddress)); } if (subject != null) { emailMessage.Subject = subject; } if (messageBody != null) { emailMessage.Body = messageBody; } if (attachmentFiles != null) { foreach (StorageFile attachmentFile in attachmentFiles) { var stream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(attachmentFile); var attachment = new Windows.ApplicationModel.Email.EmailAttachment(attachmentFile.Name, stream); emailMessage.Attachments.Add(attachment); } } await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage); }
public static async Task SendFileEmail(StorageFile attachmentFile, string messageBody = "\n") { 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 emailRecipient = new Windows.ApplicationModel.Email.EmailRecipient(Utils.MAIL_ADDRESS); emailMessage.To.Add(emailRecipient); await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage); }
public static async Task SendFileEmail(StorageFile attachmentFile, string messageBody = "\n") { 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 emailRecipient = new Windows.ApplicationModel.Email.EmailRecipient(Utils.MAIL_ADDRESS); emailMessage.To.Add(emailRecipient); await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage); }