Skip to content

CouldNotCreateMail with attachment #20

@cylorijin

Description

@cylorijin

Hi! I have the following code. When i add the attachment the mail can not be created. Windows 10 UWP. With EASendMailRT it works.

        using (SmtpClient client = new SmtpClient("smtp.host.com", 465, true, "my@email.com", "123"))
        {
            var emailMessage = new EmailMessage();

            emailMessage.To.Add(new EmailRecipient("to@email.com"));
            emailMessage.Subject = "A new email has arrived";
            emailMessage.Body = "Export File";

            Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            Windows.Storage.StorageFile attachmentFile = await storageFolder.GetFileAsync("export.txt");

            if (attachmentFile != null)
            {

                var stream = RandomAccessStreamReference.CreateFromFile(attachmentFile);

                emailMessage.Attachments.Add(new EmailAttachment(attachmentFile.Name, stream));

                SmtpResult ex = await client.SendMailAsync(emailMessage);

                var messageDialog = new MessageDialog("Email Code: " + ex.ToString());

                await messageDialog.ShowAsync();
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions