I am trying to send an encrypted email using Microsoft.Exchange
public void SendMessage(FacadeModel.EmailMessage message)
    {
        var item = new EWS.EmailMessage(_mailService);
        var handler = new SecureMimeMessageHandler();
        byte[] con = handler.encry("test", "me@mail.com.au");
        item.MimeContent = new EWS.MimeContent(Encoding.ASCII.HeaderName, con);
        item.ToRecipients.Add("me@mail.com.au");
        item.From = new EWS.EmailAddress("", "me@mail.com.au");
        item.Body = "test";
        item.Send();
}
public byte[] encry(string body, string to)
    {
        var store = new X509Store(StoreLocation.LocalMachine);
                store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
                X509Certificate2Collection certs = store.Certificates;
                X509Certificate2 cert1 = GetMatchingCertificate(certs[1], "me@mail.com.au", X509KeyUsageFlags.KeyEncipherment);
        StringBuilder msg = new StringBuilder();
        msg.AppendLine(string.Format("Content-Type: application/pkcs7-mime; smime-type=signed-data;name=smime.p7m"));
        msg.AppendLine("Content-Transfer-Encoding: 7bit");
        msg.AppendLine();
        msg.AppendLine(body);
        EnvelopedCms envelope = new EnvelopedCms(new ContentInfo(Encoding.UTF8.GetBytes(msg.ToString())));
        CmsRecipient recipient = new CmsRecipient(SubjectIdentifierType.IssuerAndSerialNumber, cert1);
        envelope.Encrypt(recipient);
        return envelope.Encode();
    }
But still i am getting a plain email with no encryption in outlook. where have i gone wrong?
- Edited by nipu7 Wednesday, February 25, 2015 3:14 AM
 Other recent topics
			Other recent topics
		

