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

creating incorrect msg file if the email body is html #136

Open
satishmarisetti123 opened this issue Oct 17, 2024 · 1 comment
Open

creating incorrect msg file if the email body is html #136

satishmarisetti123 opened this issue Oct 17, 2024 · 1 comment
Assignees

Comments

@satishmarisetti123
Copy link

Current solution is:
1.create msg file using MsgKit Nuget package.
2.Applying sensitivity label using Microsoft information protection SDK to the msg file created.
3.Read from, to, subject, body and attachment info from encrypted email message and pass this to send grid API to send email.
4.This is working fine when email body is plain text.
5.Problem occurs when email body contains html content, cannot view the contents of the received email.

We reached out to MIP support team, they figured out it is due to incorrect msg file created by MsgKit when email body is html content. But not sure exactly what is going wrong with msg file.

Please let us know you need any more information to investigate this issue.

below is the sample code of how msg file is being created.

public class CompoundFileHandler : ICompoundFileHandler
{
public System.IO.Stream CreateMsgFile(ProtectedEmailMessage message)
{
var sender = new Sender(message.From.Address, message.From.Name);
using var email = new Email(sender, message.Subject);
if (message.BodyType == BodyType.Text)
{
email.BodyText = message.Body;
}
else
{
email.BodyHtml = message.Body;
}

     foreach (var to in message.Recipients)
     {
         email.Recipients.AddTo(to.Address, to.Name);
     }

     foreach (var cc in message.RecipientsCopy)
     {
         email.Recipients.AddCc(cc.Address,cc.Name);
     }

     foreach (var bcc in message.RecipientsBlindCopy)
     {
         email.Recipients.AddBcc(bcc.Address, bcc.Name);
     }

     foreach (var attachment in message.Attachments ?? Enumerable.Empty<LoadedAttachment>())
     {
         email.Attachments.Add(attachment.Stream, attachment.Name,isInline:attachment.IsInline, contentId: attachment.Id.ToString());
     }

     var result = new MemoryStream();
     email.Save(result);
     result.Seek(0, SeekOrigin.Begin);
     return result;
 }
@Sicos1977
Copy link
Owner

It probably has to do with the way how I embed the HTML into RTF but without a good explantion from MIP (whatever that is) I dont know how to fix it.

@Sicos1977 Sicos1977 self-assigned this Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants