Ejemplo n.º 1
0
        /// <summary>
        /// Creates the mail message from entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public static MailMessageEx CreateMailMessageFromEntity(MimeEntity entity)
        {
            MailMessageEx message = new MailMessageEx();
            string        value;

            foreach (string key in entity.Headers.AllKeys)
            {
                value = entity.Headers[key];
                if (value.Equals(string.Empty))
                {
                    value = " ";
                }
                HY.Common.Utility.Utils.Logger.Log.Debug("key=" + key + "\t\t\t(thread-topic在日立会有乱码,导致exception,目前只是简单skip)");
                HY.Common.Utility.Utils.Logger.Log.Debug("value=" + value);
                if (key.ToLowerInvariant().IndexOf("thread-topic") == -1)  //thread-topic的value如是中文,在日立出现了乱码,而不是编码后的东东。既然thread-topic在邮件审批中肯定用不到,所以先忽略之
                {
                    message.Headers.Add(key.ToLowerInvariant(), value);
                }

                switch (key.ToLowerInvariant())
                {
                case MailHeaders.Bcc:
                    MailMessageEx.PopulateAddressList(value, message.Bcc);
                    break;

                case MailHeaders.Cc:
                    MailMessageEx.PopulateAddressList(value, message.CC);
                    break;

                case MailHeaders.From:
                    message.From = MailMessageEx.CreateMailAddress(value);
                    break;

                case MailHeaders.ReplyTo:
                    message.ReplyTo = MailMessageEx.CreateMailAddress(value);
                    break;

                case MailHeaders.Subject:
                    message.Subject = value;
                    break;

                case MailHeaders.To:
                    MailMessageEx.PopulateAddressList(value, message.To);
                    break;
                }
            }

            return(message);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the mail message from entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public static MailMessageEx CreateMailMessageFromEntity(MimeEntity entity)
        {
            MailMessageEx message = new MailMessageEx();
            string        value;

            foreach (string key in entity.Headers.AllKeys)
            {
                value = entity.Headers[key];
                if (value.Equals(string.Empty))
                {
                    value = " ";
                }

                message.Headers.Add(key.ToLowerInvariant(), value);

                switch (key.ToLowerInvariant())
                {
                case MailHeaders.Bcc:
                    MailMessageEx.PopulateAddressList(value, message.Bcc);
                    break;

                case MailHeaders.Cc:
                    MailMessageEx.PopulateAddressList(value, message.CC);
                    break;

                case MailHeaders.From:
                    message.From = MailMessageEx.CreateMailAddress(value);
                    break;

                case MailHeaders.ReplyTo:
                    message.ReplyTo = MailMessageEx.CreateMailAddress(value);
                    break;

                case MailHeaders.Subject:
                    message.Subject = value;
                    break;

                case MailHeaders.To:
                    MailMessageEx.PopulateAddressList(value, message.To);
                    break;
                }
            }

            return(message);
        }