示例#1
0
        /// <summary>
        /// Returns serializable attachment
        /// </summary>
        /// <param name="att"></param>
        /// <returns></returns>
        public static SerializableAttachment GetSerializeableAttachment(Attachment att)
        {
            if (att == null)
            {
                return(null);
            }

            var serializedAttachment = new SerializableAttachment
            {
                serializedContentDisposition = SerializableContentDisposition.GetSerializableContentDisposition(att.ContentDisposition),
                contentId = att.ContentId
            };

            if (att.ContentStream != null)
            {
                var bytes = new byte[att.ContentStream.Length];
                att.ContentStream.Read(bytes, 0, bytes.Length);

                serializedAttachment.serializedContentStream = new MemoryStream(bytes);
            }

            serializedAttachment.name = att.Name;
            serializedAttachment.serializedContentType = SerializableContentType.GetSerializableContentType(att.ContentType);
            serializedAttachment.nameEncoding          = att.NameEncoding;
            serializedAttachment.transferEncoding      = att.TransferEncoding;
            return(serializedAttachment);
        }
示例#2
0
        /// <summary>
        /// Serializable Mail Message Contstructor
        /// </summary>
        /// <param name="mailMessage">Original Mail Message to be serialized</param>
        public SerializableMailMessage(MailMessage mailMessage)
        {
            MailID              = Guid.NewGuid().ToString();
            this.IsBodyHtml     = mailMessage.IsBodyHtml;
            this.Body           = mailMessage.Body;
            this.Subject        = mailMessage.Subject;
            this.SerializedFrom = SerializableMailAddress.GetSerializableMailAddress(mailMessage.From);

            this.serializedTo = new List <SerializableMailAddress>();
            foreach (var ma in mailMessage.To)
            {
                this.serializedTo.Add(SerializableMailAddress.GetSerializableMailAddress(ma));
            }

            this.serializedBcc = new List <SerializableMailAddress>();
            foreach (var ma in mailMessage.Bcc)
            {
                this.serializedBcc.Add(SerializableMailAddress.GetSerializableMailAddress(ma));
            }

            this.serializedCC = new List <SerializableMailAddress>();
            foreach (var ma in mailMessage.CC)
            {
                this.serializedCC.Add(SerializableMailAddress.GetSerializableMailAddress(ma));
            }

            this.serializedReplyTo = new List <SerializableMailAddress>();
            foreach (var ma in mailMessage.ReplyToList)
            {
                this.serializedReplyTo.Add(SerializableMailAddress.GetSerializableMailAddress(ma));
            }

            this.serializedAttachments = new List <SerializableAttachment>();
            foreach (var att in mailMessage.Attachments)
            {
                this.serializedAttachments.Add(SerializableAttachment.GetSerializeableAttachment(att));
            }

            this.bodyEncoding = mailMessage.BodyEncoding;

            this.serializedDeliveryNotificationOptions = mailMessage.DeliveryNotificationOptions;
            this.serializedHeaders = SerializableCollection.GetSerializableCollection(mailMessage.Headers);
            this.mailPriority      = mailMessage.Priority;
            this.SerializedSender  = SerializableMailAddress.GetSerializableMailAddress(mailMessage.Sender);
            this.subjectEncoding   = mailMessage.SubjectEncoding;

            foreach (var av in mailMessage.AlternateViews)
            {
                this.serializedAlternateViews.Add(SerializableAlternateView.GetSerializableAlternateView(av));
            }
        }