Exemplo n.º 1
0
        private static void SaveAsMsg(string folderPath, List <Email> messages)
        {
            foreach (var msg in messages)
            {
                var email = new MsgKit.Email(new MsgKit.Sender(msg.Sender.EmailAddress, msg.Sender.Name), msg.Subject)
                {
                    BodyHtml = msg.Html,
                    BodyText = msg.Message,
                    SentOn   = msg.Date,
                };
                User rec;
                for (int i = 0; i < msg.Recipient.Count; i++)
                {
                    rec = msg.Recipient[i];
                    email.Recipients.AddTo(rec.EmailAddress, rec.Name);
                }

                switch (msg.State)
                {
                case MessageState.Read:
                    email.IconIndex = MsgKit.Enums.MessageIconIndex.ReadMail;
                    break;

                case MessageState.Unread:
                    email.IconIndex = MsgKit.Enums.MessageIconIndex.NewMail;
                    break;

                case MessageState.Send:
                    email.IconIndex = MsgKit.Enums.MessageIconIndex.ForwardedMail;
                    break;

                case MessageState.None:
                    break;
                }
                string filePath;
                foreach (var msgAtachment in msg.Atachments)
                {
                    filePath = msgAtachment.Name;
                    email.Attachments.Add(msgAtachment, Path.GetFileName(filePath));
                }
                using (var file = File.Open(Path.Combine(folderPath, Path.GetRandomFileName() + ".msg"), FileMode.CreateNew, FileAccess.Write))
                    email.Save(file);
            }
        }
        public static void ConverteToMsg(ApiEmail emails, List <Attachment> attac, string folderPath)
        {
            var email = new MsgKit.Email(new MsgKit.Sender(emails.Sender.EmailAddress, emails.Sender.Name), emails.Subject)
            {
                BodyHtml = emails.Html,
                BodyText = emails.Message,
                SentOn   = emails.Date,
            };
            User rec;

            for (int i = 0; i < emails.Recipient.Count; i++)
            {
                rec = emails.Recipient[i];
                email.Recipients.AddTo(rec.EmailAddress, rec.Name);
            }

            switch (emails.State)
            {
            case MessageState.Read:
                email.IconIndex = MsgKit.Enums.MessageIconIndex.ReadMail;
                break;

            case MessageState.Unread:
                email.IconIndex = MsgKit.Enums.MessageIconIndex.NewMail;
                break;

            case MessageState.Send:
                email.IconIndex = MsgKit.Enums.MessageIconIndex.ForwardedMail;
                break;

            case MessageState.None:
                break;
            }
            string filePath;

            foreach (var msgAtachment in attac)
            {
                filePath = msgAtachment.path;
                FileStream fstream = new FileStream(filePath + msgAtachment.namestr, FileMode.OpenOrCreate);
                email.Attachments.Add(fstream, msgAtachment.namestr);
            }
            using (var file = File.Open(Path.Combine(folderPath, Path.GetRandomFileName() + ".msg"), FileMode.CreateNew, FileAccess.Write))
                email.Save(file);
        }