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

Sending attachments results in attachment being either empty or corrupted #467

Closed
gswartz777 opened this issue Feb 22, 2019 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@gswartz777
Copy link

gswartz777 commented Feb 22, 2019

Describe the bug
We're using amazon SES to send emails. MailKit is being used since we need attachments and amazon smtp doesn't support attachments easily. Much of our code news up a MailMessage and sends it to another class that does the sending, so rather than update all of that code that calls the class, I'm trying to update the sending class to transform the MailMessage to a MimeMessage. This works for everything but attachments.

I was asked on SO to post here simply calling the WriteTo method to a local file to see what happens. I'm not sure if that's supposed to write the email to the file and also save the attachment along side it or what.

To Reproduce
Create a txt file on your desktop and update the reference to it in this code below. Run it.

internal class Program
{
    private static void Main(string[] args)
    {
        var s = GetFileStream();
        var m = new MailMessage();

        var sender = new MailAddress("info@testsite.com", "info");
        m.From = sender;
        m.Sender = sender;
        m.Body = "test email";
        m.Subject = "test subject";
        m.To.Add("test@test.com");
        m.Attachments.Add(new Attachment(s, "testfile.txt"));

        var mp = MimeMessage.CreateFromMailMessage(m);
        mp.WriteTo(@"C:\Users\youruser\Desktop\testfile2.txt");
    }

    private static MemoryStream GetFileStream()
    {
        var stream = new MemoryStream();
        var fileStream = File.Open(@"C:\Users\youruser\Desktop\testfile.txt", FileMode.Open);
        fileStream.CopyTo(stream);
        fileStream.Close();
        return stream;
    }
}

Expected behavior
Expect to have emails sent with attachments that can open properly.

Desktop (please complete the following information):

  • OS: Windows 10 Professional
@jstedfast jstedfast added the bug Something isn't working label Feb 22, 2019
@jstedfast
Copy link
Owner

Thanks for filing this bug report. I'm hoping to make a new release this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants