通过Exchange Web Services编写加密邮件 [英] Writing an encrypted mail via Exchange Web Services

查看:202
本文介绍了通过Exchange Web Services编写加密邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#发送带有Exchange WEb服务的加密电子邮件消息。
有什么可能吗?
感谢

编辑:

我的邮件正文加密:

I would like to send an encrypted EMail Message with Exchange WEb Services using C#. Is there any possibillity? Thanks

My Mail body encrypter:

        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();


推荐答案

如果您是指S / Mime加密,您必须根据 RFC 3852 RFC 4134 。完成之后,您可以发送消息。

If you are referring to S/Mime encryption, then you'll have to create the encrypted message according to RFC 3852 and RFC 4134. After you've done that, you can send the message.

使用EWS Managed API,可按如下方式完成:

Using the EWS Managed API, this can be done as follows:

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

编辑:
您应该添加标题头,如From,To,Date,Subject,等等和内容类型。

You should add the standard headers like From, To, Date, Subject, etc. And the content-type.

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正文。

Just use a StringWriter put all that together. The result is your MIME body.

这篇关于通过Exchange Web Services编写加密邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆