Написание зашифрованной почты через Exchange Web Services - PullRequest
1 голос
/ 28 сентября 2011

Я хотел бы отправить зашифрованное сообщение электронной почты с помощью веб-служб Exchange, используя C #.Есть ли возможность?Спасибо
Редактировать:
Мой почтовый шифровщик тела:

        public static byte[] encry(string body, ContentTyp typ, string to )
    {
        X509Certificate2 cert = GetMailCertificate(to);
        StringBuilder msg = new StringBuilder();
        msg.AppendLine(string.Format("Content-Type: text/{0}; charset=\"iso-8859-1\"", typ.ToString()));
        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, cert);
        envelope.Encrypt(recipient);
        //System.IO.MemoryStream ms = new System.IO.MemoryStream(envelope.Encode());
        return envelope.Encode();
    }

Основной

 byte [] con = encrypted.encry("test", encrypted.ContentTyp.plain, "test@server.com");
        EmailMessage msg1 = new EmailMessage(_server);
        msg1.MimeContent = new MimeContent("UTF-8", con);
        msg1.ToRecipients.Add("user@server.com");

        msg1.InternetMessageHeaders = ??
        msg1.Send();

1 Ответ

0 голосов
/ 30 сентября 2011

Если вы имеете в виду шифрование S / Mime, вам придется создать зашифрованное сообщение в соответствии с RFC 3852 и RFC 4134 . После этого вы можете отправить сообщение.

Используя EWS Managed API, это можно сделать следующим образом:

var item = new EmailMessage(service);
item.MimeContent = new MimeContent(Encoding.ASCII.HeaderName, content);
// Set recipient infos, etc.
item.Send();

EDIT: Вы должны добавить стандартные заголовки, такие как From, To, Date, Subject и т. Д. И тип содержимого.

Subject: Test
From: "sender" <sender@yourcompany.com>
To: "recipient" <recipient@othercompany.com>
Content-Type: application/pkcs7-mime; smime-type=signed-data; name=smime.p7m
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=smime.p7m

Your encrypted body goes here

Просто используйте StringWriter, чтобы собрать все это вместе. Результат - ваше тело MIME.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...