Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CouldNotCreateMail with attachment #20

Open
cylorijin opened this issue Dec 6, 2018 · 5 comments
Open

CouldNotCreateMail with attachment #20

cylorijin opened this issue Dec 6, 2018 · 5 comments

Comments

@cylorijin
Copy link

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, "[email protected]", "123"))
        {
            var emailMessage = new EmailMessage();

            emailMessage.To.Add(new EmailRecipient("[email protected]"));
            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();
            }
        }
@Vangos
Copy link
Member

Vangos commented Dec 10, 2018

Hello and thank you for creating the ticket. Could you please provide me with the following information:

  1. What is the SmtpResult code?
  2. What is the size of the attachment?

@cylorijin
Copy link
Author

Hi! Thanks four your response. The SmtpResult is "CouldNotCreateMail" and the file size is 16KB.

@jbastidasDNC
Copy link

Hi, any updates about this issue?. I am having same problem.

@Vangos
Copy link
Member

Vangos commented Jun 21, 2019

I have not been able to reproduce. I assume the mail server could block potential attachments.

@jbastidasDNC
Copy link

jbastidasDNC commented Jun 22, 2019

Hi again. In my case I am using 1and1 smtp server (smtp.1and1.es). It was responding 501 syntax error - line too long after I send message section:

SmtpResponse repsonseMessage = await Socket.Send(await BuildSmtpMailInput(message));

I notice it was because fileEncoded was very long to 1and1 smtp restriction. So I modifyed BuildSmtpMailInput method

                string fileEncoded = await _encodeToBase64(attachment.Data);
                List<string> splitData = new List<string>(Regex.Split(fileEncoded, @"(?<=\G.{100})", RegexOptions.Singleline));
                string splitFile = "";
                foreach (var s in splitData)
                {
                    splitFile += s + Environment.NewLine;
                }
                mailInput.Append(Environment.NewLine);
                mailInput.Append(splitFile);
                mailInput.Append(Environment.NewLine);

It worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants