Using UWP with C# how can you send an email with attachments using outlook

Paul Ryan 331 Reputation points
2023-12-22T22:21:25.2666667+00:00

Hi I asked this question in Nov.

Re-asking to see if anyone can provide a work around

Default Mail App - is Outlook

C# UWP

I need to send an email with attachments from a C# UWP App. Outlook opens with all the info but not the ATTACHMENTS.

thank you

private async Task ComposeEmail()
{
    var emailMessage = GetEmailMessage();
    emailMessage.Body = "Please find attached zip file ";

    emailMessage.Subject = "Reports for " + SFiles.PtRptList.PtName;
    if (ReportZipFile != null)
    {
        StorageFile attachemntFile = await StorageFile.GetFileFromPathAsync(ReportZipFile);
        var stream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(attachemntFile);
        //  var attachment = new Windows.ApplicationModel.Email.EmailAttachment(
        //              attachemntFile.Name,
        //              stream);
        //  emailMessage.Attachments.Add(attachment);
        emailMessage.SetBodyStream(EmailMessageBodyKind.Html, stream);
        
    }

    await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage);
}
Microsoft 365 and Office | Development | Other
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Thibaud Lamy 0 Reputation points
    2024-04-24T14:15:36.6166667+00:00

    Hi, i've the same issue, did you found a solution ?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.