You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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("[email protected]", "info");
m.From = sender;
m.Sender = sender;
m.Body = "test email";
m.Subject = "test subject";
m.To.Add("[email protected]");
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
The text was updated successfully, but these errors were encountered:
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.
Expected behavior
Expect to have emails sent with attachments that can open properly.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: