Exemplo n.º 1
0
        public MailMessageItem SaveMessages(int id,
                                            IEnumerable <MailAttachment> attachments,
                                            IEnumerable <string> to,
                                            IEnumerable <string> bcc,
                                            IEnumerable <string> cc,
                                            int replyToId,
                                            string from,
                                            string body,
                                            bool importance,
                                            IEnumerable <int> tags,
                                            string streamId,
                                            string subject)
        {
            if (id < 1)
            {
                id = 0;
            }

            var item = new MailSendItem
            {
                Attachments = new List <MailAttachment>(attachments),
                Bcc         = new List <string>(bcc),
                Cc          = new List <string>(cc),
                ReplyToId   = replyToId,
                From        = from,
                HtmlBody    = body,
                Important   = importance,
                Labels      = new List <int>(tags),
                StreamId    = streamId,
                Subject     = subject,
                To          = new List <string>(to)
            };

            return(SendQueue.SaveToDraft(TenantId, Username, item, id));
        }
        public MailMessageItem SaveMessages(int id,
                                            IEnumerable <MailAttachment> attachments,
                                            IEnumerable <string> to,
                                            IEnumerable <string> bcc,
                                            IEnumerable <string> cc,
                                            string mimeMessageId,
                                            string mimeReplyToId,
                                            string from,
                                            string body,
                                            bool importance,
                                            IEnumerable <int> tags,
                                            string streamId,
                                            string subject)
        {
            if (id < 1)
            {
                id = 0;
            }

            var item = new MailSendItem
            {
                Attachments   = new List <MailAttachment>(attachments),
                Bcc           = new List <string>(bcc),
                Cc            = new List <string>(cc),
                MimeReplyToId = mimeReplyToId,
                MimeMessageId = string.IsNullOrEmpty(mimeMessageId) ? MailBoxManager.CreateMessageId() : mimeMessageId,
                From          = from,
                HtmlBody      = body,
                Important     = importance,
                Labels        = new List <int>(tags),
                StreamId      = streamId,
                Subject       = subject,
                To            = new List <string>(to)
            };

            var accounts     = MailBoxManager.GetAccountInfo(TenantId, Username).ToAddressData();
            var mail_address = new MailAddress(item.From);
            var account      = accounts.FirstOrDefault(a => a.Email.ToLower().Equals(mail_address.Address));

            if (account == null)
            {
                throw new ArgumentException("no such mailbox");
            }

            return(SendQueue.SaveToDraft(TenantId, Username, item, id, account.MailboxId));
        }
Exemplo n.º 3
0
        public MailMessageItem SaveMessage(int id,
                                           IEnumerable <MailAttachment> attachments,
                                           IEnumerable <string> to,
                                           IEnumerable <string> bcc,
                                           IEnumerable <string> cc,
                                           string mimeMessageId,
                                           string mimeReplyToId,
                                           string from,
                                           string body,
                                           bool importance,
                                           IEnumerable <int> tags,
                                           string streamId,
                                           string subject)
        {
            if (id < 1)
            {
                id = 0;
            }

            var item = new MailSendItem
            {
                Attachments   = new List <MailAttachment>(attachments),
                Bcc           = new List <string>(bcc),
                Cc            = new List <string>(cc),
                MimeReplyToId = mimeReplyToId,
                MimeMessageId = string.IsNullOrEmpty(mimeMessageId) ? MailBoxManager.CreateMessageId() : mimeMessageId,
                From          = from,
                HtmlBody      = body,
                Important     = importance,
                Labels        = new List <int>(tags),
                StreamId      = streamId,
                Subject       = subject,
                To            = new List <string>(to)
            };

            var accounts    = MailBoxManager.GetAccountInfo(TenantId, Username).ToAddressData();
            var mailAddress = new MailAddress(item.From);
            var account     = accounts.FirstOrDefault(a => a.Email.ToLower().Equals(mailAddress.Address));

            if (account == null)
            {
                throw new ArgumentException("Mailbox not found");
            }

            if (account.IsGroup)
            {
                throw new InvalidOperationException("Saving emails from a group address is forbidden");
            }

            if (id > 0)
            {
                var message = GetMessage(id, false, false, false);

                if (message.Folder != MailFolder.Ids.drafts)
                {
                    throw new InvalidOperationException("Saving emails is permitted only in the Drafts folder");
                }
            }

            return(SendQueue.SaveToDraft(TenantId, Username, item, id, account.MailboxId));
        }