public SendThread(string userId, SendBox sendBox, LiteDBManager liteDb) { _userId = userId; _sendBox = sendBox; _liteDb = liteDb; // 获取设置 // 获取设置 _setting = _liteDb.SingleOrDefault <Setting>(s => s.userId == userId); _cancellationTokenSource = new CancellationTokenSource(); }
/// <summary> /// 对发件进行预处理 /// </summary> /// <param name="sendItems"></param> private void PreHandleSendItems(List <SendItem> sendItems) { if (sendItems.Count < 1) { return; } // 获取设置 Setting setting = _liteDb.SingleOrDefault <Setting>(s => s.userId == _userId); // 设置发送的内容 if (setting.sendWithImageAndHtml) { SendStatus |= SendStatus.AsImage; } else { SendStatus |= SendStatus.AsHtml; } // 奇偶混发 for (int index = 0; index < sendItems.Count; index++) { var sendItem = sendItems[index]; // 偶数发图片 // 如果被设置了发送类型,就按设置的发送类型进行发送 if (index % 2 == 0 && setting.sendWithImageAndHtml && sendItem.sendItemType == SendItemType.none) { sendItem.sendItemType = SendItemType.dataUrl; } } // 初始化进度 var sendingInfo0 = new SendingProgressInfo() { historyId = _currentHistoryGroupId, index = 0, total = sendItems.Count, }; SendingProgressInfo = sendingInfo0; }
/// <summary> /// 构造函数 /// </summary> /// <param name="subject"></param> /// <param name="receivers"></param> /// <param name="data"></param> /// <param name="templateId"></param> /// <param name="liteDb"></param> protected EmailPreview(JToken data, LiteDBManager liteDb) { LiteDb = liteDb; // 生成 Senders = data.SelectToken(Fields.senders).ValueOrDefault(new JArray()); Subject = data.SelectToken(Fields.subject).ValueOrDefault(Fields.default_); Receivers = data.SelectToken(Fields.receivers).ValueOrDefault(new JArray()); Data = data.SelectToken(Fields.data).ValueOrDefault(new JArray()); Attachments = data.SelectToken(Fields.attachments).ValueOrDefault(new JArray()).ToList().ConvertAll(item => new EmailAttachment() { fullName = item.ToString() }); CopyTo = data.SelectToken(Fields.copyToEmails).ValueOrDefault(new JArray()); string templateId = data.Value <string>(Fields.templateId); // 获取模板 Template = LiteDb.SingleOrDefault <Template>(t => t._id == templateId); }