public void TestLocalhost() { var sendItem = new SendItem { To = new List <EmailItem> { new EmailItem { Email = "*****@*****.**" } }, Host = new Host { Type = HostType.Local, Address = "localhost" }, From = new List <EmailItem> { new EmailItem { Email = "*****@*****.**" } }, Body = new Body { Content = "this is a test mail from panasia.cn" }, Subject = new Subject { Content = "测试邮件" } }; sendItem.Send(); Assert.IsNotNull(sendItem); }
/// <summary> /// Store item file on the server. /// </summary> /// <returns>Returns a bool if it can save it on the server. </returns> /// See <see cref="StoreFile"/> on how it adds a file. /// <param name="item">The item it should store</param> /// <param name="id">The id it has in the database. Used for giving it a unique id. </param> public async Task <bool> StoreItem(SendItem item, int id) { if (_db.Items.Any(x => x.Id == id)) { //Calls the delete function await DeleteFile(item.FilePath); } //Try to store the file. We receive the filepath back. var filePath = await StoreFile(ItemsUrl, ItemsPath, item.Files, id); //If the filepath is empty it could not add it. if (filePath == "") { //Return false because it failed return(false); } // Since we succeed, set the new filepath. item.FilePath = filePath; // Empty file field for safety with sending back. item.Files = null; // return true since it could add the file. return(true); }
/// <summary> /// /// </summary> /// <param name="item"></param> private void AddSendItemToListView(SendItem item) { ListViewItem lvi = this.listView1.Items.Add(item.Name); string s = HexStringConverter.Default.ConvertToObject(item.Bytes).ToString(); lvi.SubItems.Add(s); lvi.Tag = item; }
/// <summary> /// 将发送内容转成图片 /// </summary> /// <param name="sendItem"></param> private async Task <bool> ConvertToImage(Setting setting, SendItem sendItem) { if (sendItem.sendItemType == SendItemType.dataUrl && setting.sendWithImageAndHtml && string.IsNullOrEmpty(sendItem.dataUrl)) { // 从前端转存图片 ReceivedMessage message = await SendCallback.Insance.SendAsync(_userId, new Protocol.Response() { eventName = "sendingInfo", command = "html2image", result = sendItem, }); if (message == null) { return(false); } // 将结果添加到sendItem中 var dataUrl = message.JObject.SelectToken("result"); if (dataUrl == null) { return(false); } dataUrl = dataUrl.Value <string>(); sendItem.dataUrl = $"<img src=\"{dataUrl}\">"; // 更新保存的数据 _liteDb.Update(sendItem); } return(true); }
// 添加附件 private void AddAttachmenets(MailMessage mail, SendItem sendItem) { if (sendItem.attachments == null || sendItem.attachments.Count < 1) { return; } for (int i = 0; i < sendItem.attachments.Count; i++) { string pathFileName = sendItem.attachments[i].fullName.Replace('/', '\\'); var fileInfo = new FileInfo(pathFileName); if (!fileInfo.Exists) { sendItem.attachments[i].isSent = false; sendItem.attachments[i].reason = "文件不存在"; continue; } var attachment = new Attachment(pathFileName); //设置附件的MIME信息 ContentDisposition cd = attachment.ContentDisposition; cd.CreationDate = fileInfo.CreationTime; //设置附件的创建时间 cd.ModificationDate = fileInfo.LastWriteTime; //设置附件的修改时间 cd.ReadDate = fileInfo.LastAccessTime; //设置附件的访问时间 mail.Attachments.Add(attachment); //将附件添加到mailmessage对象 sendItem.attachments[i].isSent = true; } }
// 添加抄送 private void AddCopyToEmails(MailMessage mail, SendItem sendItem) { foreach (var email in sendItem.copyToEmails) { mail.CC.Add(email); } }
public void TestSendItem() { var sendItem = new SendItem { To = new List <EmailItem> { new EmailItem { Email = "*****@*****.**" } }, Host = Host, Credentials = Credentials, From = new List <EmailItem> { new EmailItem { Email = "*****@*****.**" } }, Body = new Body { Content = "this is a test mail from panasia.cn" }, Subject = new Subject { Content = "测试邮件" } }; sendItem.Send(); Assert.IsNotNull(sendItem); }
public ArrayList query_cms_item_plan_sql(string sql, out string out_log) { try { ArrayList list = new ArrayList(); SQLiteDBHelper db = new SQLiteDBHelper(this.app_path + @"\config\" + this.db_name); using (SQLiteDataReader reader = db.ExecuteReader(sql, null)) { while (reader.Read()) { SendItem sendItem = new SendItem(); sendItem.send_id = int.Parse(reader["cms_id"].ToString()); sendItem.num_iid = reader["num_iid"].ToString(); list.Add(sendItem); } } out_log = ""; return(list); } catch (Exception exception) { out_log = "出错啦:" + exception.ToString(); return(new ArrayList()); } }
public async Task <IActionResult> PostItem([FromForm] SendItem item) { //Check if the Item have another id then 0 if (item.Id != 0) { //If it is, id is something else tell them something is wrong. //This is added for error check from the front-end. return(BadRequest()); } Console.WriteLine("Item name: " + item.Name); //Check if the item model is valid // If model was not valid. Then it is a bad request. if (!ModelState.IsValid) { return(BadRequest()); } // If // Check for if the file is null. // if it is then not valid item. if (item.Files == null) { return(BadRequest()); } // Try to store the file on the correct place on server // Get the count of all values in database to get the next id. // Since we need the id before it is added in the database. // If it fail it is a bad request. if (await _rs.StoreItem(item, _db.Items.Count() + 1) == false) { return(BadRequest()); } // Get user id from the user logged in var user = await _userManager.GetUserAsync(User); Console.WriteLine("User: "******" - is logged in!"); // Set ownerId to the item item.OwnerId = user.Id; //Add item to database and saves it _db.Add(item); _db.SaveChanges(); var newItem = new Item(user, item.Name, item.Color, item.Size, item.Location, item.Price, item.Description, item.BrandName, item.Category, item.FilePath) { Id = item.Id, }; //Return the object back return(Ok(newItem)); }
public int CompareTo(object obj) { if (obj is SendItem) { SendItem temp = (SendItem)obj; return(sendIn.CompareTo(temp.sendIn)); } throw new ArgumentException("object is not a SendItem"); }
public void ScheduleSend(byte[] b, int length, EndPoint forwardEndPoint, Socket socket, int fwdIn) { SendItem si = new SendItem(); si.buffer = b; si.length = length; si.forwardEndPoint = forwardEndPoint; si.socket = socket; si.sendIn = DateTime.Now.AddMilliseconds(fwdIn); // A full implementation would include locking Sends.Add(si); Sends.Sort(); }
private void DoWork(SendItem item) { var fix = GetPubKey(item.Event); if (!string.IsNullOrEmpty(item.Prefix)) { fix = item.Prefix + "." + fix; } Publish(item.Event, fix, out _, out _, item.Enable); }
public bool insert(SendItem sendItem, out string out_log) { try { //if (this.oleDbConnection == null) //{ // this.set_pay_order_mdb(); //} DateTime now = DateTime.Now; //string cmdText = "insert into `send` (`num_iid`,`from`,`create_date`,`create_date_str`,`memo`,`status`,`sort`) values('{num_iid}','{from}','{create_date}','{create_date_str}','{memo}',{status},{sort});"; //cmdText = cmdText // .Replace("{num_iid}", sendItem.num_iid) // .Replace("{from}", sendItem.from) // .Replace("{create_date_str}", sendItem.create_date_str) // .Replace("{create_date}", ""+now) // .Replace("{memo}", sendItem.memo) // .Replace("{status}", ""+sendItem.status) // .Replace("{sort}", ""+sendItem.sort); //if (((this.oleDbCommand_send == null) || (this.oleDbCommand_send.Connection == null)) || (this.oleDbCommand_send.Connection.State != ConnectionState.Open)) //{ // this.oleDbCommand_send = new OleDbCommand(cmdText, this.oleDbConnection); //} //else //{ // this.oleDbCommand_send.CommandText = cmdText; //} //this.oleDbCommand_send.ExecuteNonQuery(); //this.oleDbCommand_send.Dispose(); string sql = "INSERT INTO send(num_iid,from_name,create_date,create_date_str,memo,status,sort,goods_type,type) values(@num_iid,@from_name,@create_date,@create_date_str,@memo,@status,@sort,@goods_type,@type)"; SQLiteDBHelper db = new SQLiteDBHelper(this.app_path + @"\config\" + this.db_name); SQLiteParameter[] parameters = new SQLiteParameter[] { new SQLiteParameter("@num_iid", sendItem.num_iid), new SQLiteParameter("@from_name", sendItem.from), new SQLiteParameter("@create_date", now), new SQLiteParameter("@create_date_str", sendItem.create_date_str), new SQLiteParameter("@memo", sendItem.memo), new SQLiteParameter("@status", sendItem.status), new SQLiteParameter("@sort", sendItem.sort), new SQLiteParameter("@goods_type", sendItem.goods_type), new SQLiteParameter("@type", sendItem.type) }; db.ExecuteNonQuery(sql, parameters); out_log = ""; return(true); } catch (Exception exception) { out_log = exception.ToString(); return(false); } }
public async Task GetSendPreview(string key) { SendItem item = InstanceCenter.EmailPreview[Token.UserId].GetPreviewHtml(key); if (item == null) { await ResponseErrorAsync("没有可预览项,请检查收件箱是否为空"); return; } await ResponseSuccessAsync(item); }
public static void tools_zhuanhua_tianjia_zhushou(CmsForm cmsForm, string content1) { try { SendItem sendItem = new SendItem(); sendItem.from = "手工添加"; sendItem.create_date_str = DateTime.Now.ToString("yyyyMMddHHmmssfff"); string content = cmsForm.webBrowser_zhuanhua.Document.Body.InnerHtml; if (string.IsNullOrEmpty(content)) { LogUtil.log_call(cmsForm, "跟发内容不能为空!"); return; } content = UrlUtil.parseContentWenan(cmsForm, content); ContentItem contentItem = UrlUtil.parseContent(cmsForm, content, null, cmsForm.checkBox_qunfa_pid.Checked, true, 0); content = contentItem.content_send; if (!string.IsNullOrEmpty(content)) { content = UrlUtil.copyImgContent(cmsForm, content, sendItem.create_date_str); sendItem.memo = CommonUtil.toText(content); string follow_path = cmsForm.appBean.follow_path + @"\" + sendItem.create_date_str; if (!Directory.Exists(follow_path)) { Directory.CreateDirectory(follow_path); } UtilFile.write(string.Concat(follow_path, "\\content.html"), content, Encoding.GetEncoding("GB2312")); ((IHTMLDocument2)cmsForm.webBrowser_zhuanhua.Document.DomDocument).body.innerHTML = ""; LogUtil.log_call(cmsForm, "添加跟发成功!"); string out_log = ""; cmsForm.sendSqlUtil.insert(sendItem, out out_log); //cmsForm.load_follow(out out_log); FollowUtil.load_call(cmsForm); } else { LogUtil.log_call(cmsForm, "跟发内容不能为空!"); } if (cmsForm.checkBox_tools_qingkong.Checked) { ((IHTMLDocument2)cmsForm.webBrowser_zhuanhua.Document.DomDocument).body.innerHTML = ""; } } catch (Exception exception) { //MessageBox.Show("[messageForThread]出错:" + exception.ToString()); } }
public ActionResult SendItem() { var listItem = new List <ItemTransaction>(); var orders = db.Orders.Where(i => i.Status == db.Statuses.FirstOrDefault(j => j.Name == "Waiting for appointment")).Include(i => i.ItemTransactions); foreach (var order in orders) { listItem.AddRange(order.ItemTransactions); } var result = new SendItem(); result.ItemTransaction = listItem; result.Employee = db.Employees.Where(i => i.Role == db.Roles.FirstOrDefault(j => j.Name == "Engineer")).ToList(); return(View(result)); }
public void SendOneItem() { for (int i = 0; i < Sends.Count; i++) { SendItem si = Sends[i]; if (si != null && si.sendIn < DateTime.Now) { Console.WriteLine("sending {0} {1} {2}", i, (DateTime.Now - si.sendIn).TotalMilliseconds, si.buffer[0]); // should send //rfd.ForwardSocket.SendTo(b, length, si.socket.SendTo(si.buffer, si.length, SocketFlags.None, si.forwardEndPoint); Sends.Remove(si); } } }
public static void qunfa_shoudong_gengfa(CmsForm cmsForm, string content1) { try { SendItem sendItem = new SendItem(); sendItem.from = "手工添加"; sendItem.create_date_str = DateTime.Now.ToString("yyyyMMddHHmmssfff"); string content = cmsForm.webBrowser_send_content.Document.Body.InnerHtml; //ContentItem contentItem = UrlUtil.parseContent(this,content); //sendItem.num_iid = contentItem.num_iid; if (!string.IsNullOrEmpty(content)) { content = UrlUtil.copyImgContent(cmsForm, content, sendItem.create_date_str); sendItem.memo = CommonUtil.toText(content); string follow_path = cmsForm.appBean.follow_path + @"\" + sendItem.create_date_str; if (!Directory.Exists(follow_path)) { Directory.CreateDirectory(follow_path); } UtilFile.write(string.Concat(follow_path, "\\content_wenan.html"), UrlUtil.parseContentWenan(cmsForm, content), Encoding.GetEncoding("GB2312")); UtilFile.write(string.Concat(follow_path, "\\content_img.html"), UrlUtil.parseImg(cmsForm, content), Encoding.GetEncoding("GB2312")); UtilFile.write(string.Concat(follow_path, "\\content.html"), content, Encoding.GetEncoding("GB2312")); ((IHTMLDocument2)cmsForm.webBrowser_send_content.Document.DomDocument).body.innerHTML = ""; LogUtil.log_call(cmsForm, "添加跟发成功!"); string out_log = ""; cmsForm.sendSqlUtil.insert(sendItem, out out_log); FollowUtil.load_call(cmsForm); } else { LogUtil.log_call(cmsForm, "跟发内容不能为空!"); } } catch (Exception exception) { //MessageBox.Show("[messageForThread]出错:" + exception.ToString()); } }
// 生成发送消息的消息体 private async Task <MailMessage> GenerateMailMessage(SendItem sendItem) { //确定发件地址与收件地址 MailAddress sendAddress = new MailAddress(_sendBox.email); // 判断是否需要转成图片 await ConvertToImage(_setting, sendItem); MailAddress receiveAddress = new MailAddress(sendItem.receiverEmail); //构造一个Email的Message对象 内容信息 MailMessage mailMessage = new MailMessage(sendAddress, receiveAddress) { Subject = sendItem.subject, SubjectEncoding = Encoding.UTF8 }; // 设置发件主体 if (sendItem.sendItemType == SendItemType.dataUrl && !string.IsNullOrEmpty(sendItem.dataUrl)) { mailMessage.Body = sendItem.dataUrl; } else { mailMessage.Body = sendItem.html; } // 发件编码 mailMessage.BodyEncoding = Encoding.UTF8; mailMessage.IsBodyHtml = true; // 伪装成 outlook 发送 AddCustomHeaders(mailMessage); // 添加附件 AddAttachmenets(mailMessage, sendItem); // 添加抄送 AddCopyToEmails(mailMessage, sendItem); return(mailMessage); }
private void HandleSend(SendItem item) { if (!m_clients.TryGetValue(item.Index, out var token)) { return; } SocketAsyncEventArgs sendEventArg = null; m_mutex.WaitOne(); try { if (m_sendPool.Count == 0) { SocketAsyncEventArgs tmp = new SocketAsyncEventArgs(); tmp.Completed += new EventHandler <SocketAsyncEventArgs>(IO_Completed); m_sendPool.Push(tmp); } sendEventArg = m_sendPool.Pop(); sendEventArg.UserToken = token; } catch { } finally { m_mutex.Release(); } try { sendEventArg.SetBuffer(item.data, 0, item.length); bool willRaiseEvent = token.Socket.SendAsync(sendEventArg); if (!willRaiseEvent) { ProcessSend(sendEventArg); } } catch (ObjectDisposedException ex) { ((IHPSocketServer)this).OnClose?.BeginInvoke(item.Index, null, null); } item = null; }
/// <summary> /// /// </summary> /// <param name="sendItem"></param> public frmSendData(SendItem sendItem) { if (sendItem == null) { throw new ArgumentNullException("sendItem"); } InitializeComponent(); this.SendItem = sendItem; this.IsEdit = true; this.txtName.Text = this.SendItem.Name; this.txtDatas.Text = HexStringConverter.Default.ConvertToObject(this.SendItem.Bytes).ToString(); this.Text = string.Format( "{0} - {1}", this.Text, Strings.Edit); }
public ArrayList query_send_item_sql(string sql, out string out_log) { try { ArrayList list = new ArrayList(); //OleDbDataReader reader = new OleDbCommand(sql, this.oleDbConnection).ExecuteReader(); //while (reader.Read()) //{ // SendItem sendItem = new SendItem(); // sendItem.send_id = int.Parse(reader["send_id"].ToString()); // sendItem.num_iid = reader["num_iid"].ToString(); // list.Add(sendItem); //} //reader.Close(); SQLiteDBHelper db = new SQLiteDBHelper(this.app_path + @"\config\" + this.db_name); using (SQLiteDataReader reader = db.ExecuteReader(sql, null)) { while (reader.Read()) { SendItem sendItem = new SendItem(); sendItem.send_id = int.Parse(reader["send_id"].ToString()); sendItem.num_iid = reader["num_iid"].ToString(); list.Add(sendItem); } } out_log = ""; return(list); } catch (Exception exception) { out_log = "出错啦:" + exception.ToString(); return(new ArrayList()); } }
public static void load_item(CmsForm cmsForm, SendItem sendItem) { try { if (cmsForm.dataGridViewFollowSnd.InvokeRequired) { load_item method = new load_item(FollowUtil.load_item); cmsForm.BeginInvoke(method, new object[] { cmsForm, sendItem }); } else { DataGridViewRow dataGridViewRow = new DataGridViewRow(); //cmsForm.dataGridViewFollowSnd.Rows[i].HeaderCell.Value = string.Concat(i + 1, ""); DataGridViewTextBoxCell create_date_str = new DataGridViewTextBoxCell(); create_date_str.Value = sendItem.create_date_str; create_date_str.Tag = sendItem; dataGridViewRow.Cells.Add(create_date_str); DataGridViewTextBoxCell from = new DataGridViewTextBoxCell(); from.Value = sendItem.from; dataGridViewRow.Cells.Add(from); DataGridViewTextBoxCell memo = new DataGridViewTextBoxCell(); memo.Value = sendItem.memo; dataGridViewRow.Cells.Add(memo); DataGridViewTextBoxCell status = new DataGridViewTextBoxCell(); status.Value = (sendItem.status == 0 ? "未发送" : "已发送"); dataGridViewRow.Cells.Add(status); //DataGridViewComboBoxCell comboxcell = new DataGridViewComboBoxCell(); //row.Cells.Add(comboxcell); //cmsForm.dataGridViewFollowSnd[0, i].Value = sendItem.create_date_str; //cmsForm.dataGridViewFollowSnd[1, i].Value = sendItem.from; //cmsForm.dataGridViewFollowSnd[2, i].Value = sendItem.memo; //cmsForm.dataGridViewFollowSnd[3, i].Value = (sendItem.status == 0 ? "未发送" : "已发送"); //LogUtil.log_call(this, "sendItem.create_date:" + sendItem.create_date); //this.dataGridViewFollowSnd[2, string0].Value = GClass13.smethod_15(arrayList26.string_2); //this.dataGridViewFollowSnd[2, string0].Style.ForeColor = GClass13.smethod_16(arrayList26.string_2); //cmsForm.dataGridViewFollowSnd[0, i].Tag = sendItem; cmsForm.dataGridViewFollowSnd.Rows.Add(dataGridViewRow); //string out_log = ""; //ArrayList follow_list = cmsForm.sendSqlUtil.query_send(0, out out_log); //cmsForm.dataGridViewFollowSnd.Rows.Clear(); //if (follow_list != null && follow_list.Count > 0) //{ // int i = 0; // foreach (SendItem sendItem in follow_list) // { // DataGridViewRow dataGridViewRow = new DataGridViewRow(); // cmsForm.dataGridViewFollowSnd.Rows.Add(dataGridViewRow); // cmsForm.dataGridViewFollowSnd.Rows[i].HeaderCell.Value = string.Concat(i + 1, ""); // cmsForm.dataGridViewFollowSnd[0, i].Value = sendItem.create_date_str; // cmsForm.dataGridViewFollowSnd[1, i].Value = sendItem.from; // cmsForm.dataGridViewFollowSnd[2, i].Value = sendItem.memo; // cmsForm.dataGridViewFollowSnd[3, i].Value = (sendItem.status == 0 ? "未发送" : "已发送"); // //LogUtil.log_call(this, "sendItem.create_date:" + sendItem.create_date); // //this.dataGridViewFollowSnd[2, string0].Value = GClass13.smethod_15(arrayList26.string_2); // //this.dataGridViewFollowSnd[2, string0].Style.ForeColor = GClass13.smethod_16(arrayList26.string_2); // cmsForm.dataGridViewFollowSnd[0, i].Tag = sendItem; // i++; // } //} } } catch (Exception exception) { MessageBox.Show("[messageForThread]出错:" + exception.ToString()); } }
/// <summary> /// /// </summary> private void SelectSendItem() { ListViewItem lvi= GetSelectedListViewItem(); if (lvi != null) { SendItem item = lvi.Tag as SendItem; this._selectedSendItem = item; this.DialogResult = DialogResult.OK; this.Close(); } else { SelectListViewItemFirst(); return; } }
void SendAdd_Click(object sender, EventArgs e) { byte[] bs ; if (this.GetSendBytes(out bs)) { SendItem item = new SendItem(); item.Name = HexStringConverter.Default.ConvertToObject(bs).ToString(); item.Bytes = bs; frmSendData f = new frmSendData(item); if (f.ShowDialog() == DialogResult.OK) { this.SendCollection.Add(item); CreateContextMenu(); } } }
public ArrayList query_send_sql(string sql, out string out_log) { try { ArrayList list = new ArrayList(); //OleDbDataReader reader = new OleDbCommand(sql, this.oleDbConnection).ExecuteReader(); //while (reader.Read()) //{ // SendItem sendItem = new SendItem(); // sendItem.send_id = int.Parse(reader["send_id"].ToString()); // sendItem.from = reader["from"].ToString(); // sendItem.num_iid = reader["num_iid"].ToString(); // sendItem.memo = reader["memo"].ToString(); // sendItem.create_date_str = reader["create_date_str"].ToString(); // sendItem.create_date = DateTime.Parse(reader["create_date"].ToString()); // sendItem.status = int.Parse(reader["status"].ToString()); // sendItem.sort = int.Parse(reader["sort"].ToString()); // list.Add(sendItem); //} //reader.Close(); SQLiteDBHelper db = new SQLiteDBHelper(this.app_path + @"\config\" + this.db_name); using (SQLiteDataReader reader = db.ExecuteReader(sql, null)) { while (reader.Read()) { //Console.WriteLine("ID:{0},TypeName{1}", reader.GetInt64(0), reader.GetString(1)); SendItem sendItem = new SendItem(); //sendItem.send_id = int.Parse(reader["send_id"].ToString()); //sendItem.from = reader["from_name"].ToString(); //sendItem.num_iid = reader["num_iid"].ToString(); //sendItem.memo = reader["memo"].ToString(); //sendItem.create_date_str = reader["create_date_str"].ToString(); //sendItem.create_date = DateTime.Parse(reader["create_date"].ToString()); //sendItem.status = int.Parse(reader["status"].ToString()); //sendItem.sort = int.Parse(reader["sort"].ToString()); try { sendItem.send_id = reader.GetInt32(0); } catch (Exception) { } try { sendItem.num_iid = reader.GetString(1); } catch (Exception) { } try { sendItem.from = reader.GetString(2); } catch (Exception) { } try { sendItem.create_date_str = reader.GetString(3); } catch (Exception) { } try { sendItem.create_date = reader.GetDateTime(4); } catch (Exception) { } try { sendItem.memo = reader.GetString(5); } catch (Exception) { } try { sendItem.status = reader.GetInt16(6); } catch (Exception) { } try { sendItem.sort = reader.GetInt16(7); } catch (Exception) { } try { sendItem.goods_type = reader.GetString(8); } catch (Exception) { } try { sendItem.type = reader.GetInt16(9); } catch (Exception) { } list.Add(sendItem); } } out_log = ""; return(list); } catch (Exception exception) { out_log = "出错啦:" + exception.ToString(); return(new ArrayList()); } }
public static void sendGroup(CmsForm cmsForm, string content_json) { if (!cmsForm.appBean.gengfa_qun) { return; } if (cmsForm.appBean.qunfa_genfa_status == false) { return; } JsonData sync_resul = JsonMapper.ToObject(content_json) as JsonData; string content = sync_resul["content"].ToString(); string group = sync_resul["group"].ToString(); string qq = sync_resul["qq"].ToString(); ArrayList textBox_qun_list = QQqunUtil.findGroup(cmsForm); ArrayList textBox_qun_guolv = QQqunUtil.findGroup_guolv(cmsForm); ArrayList textBox_qun_del = QQqunUtil.findGroup_del(cmsForm); string sbf = ""; if (textBox_qun_list.Contains(group)) { if (!string.IsNullOrEmpty(content)) { string[] sArray = Regex.Split(content, "\n", RegexOptions.IgnoreCase); foreach (string i in sArray) { if (QQqunUtil.isContains(textBox_qun_del, i)) { break; } if (QQqunUtil.isContains(textBox_qun_guolv, i)) { continue; } sbf = sbf + i; } } LogUtil.log_qun_call(cmsForm, "content:" + content); if (!string.IsNullOrEmpty(sbf)) { SendItem sendItem = new SendItem(); sendItem.from = "群:" + group; sendItem.create_date_str = DateTime.Now.ToString("yyyyMMddHHmmssfff"); content = sbf; content = QQqunUtil.parseContentWenan(cmsForm, content); if (!string.IsNullOrEmpty(content)) { //content = UrlUtil.copyImgContent(this, content, sendItem.create_date_str); sendItem.memo = CommonUtil.toText(content); FollowUtil.load_item(cmsForm, sendItem); string follow_path = cmsForm.appBean.follow_path + @"\" + sendItem.create_date_str; if (!Directory.Exists(follow_path)) { Directory.CreateDirectory(follow_path); } //UtilFile.write(string.Concat(follow_path, "\\content_wenan.html"), UrlUtil.parseContentWenan(this, content), Encoding.GetEncoding("GB2312")); //UtilFile.write(string.Concat(follow_path, "\\content_img.html"), UrlUtil.parseImg(this, content), Encoding.GetEncoding("GB2312")); UtilFile.write(string.Concat(follow_path, "\\content.html"), content, Encoding.GetEncoding("GB2312")); //((IHTMLDocument2)this.webBrowser_send_content.Document.DomDocument).body.innerHTML = ""; //LogUtil.log_call(this,"---------------------"); string out_log; cmsForm.sendSqlUtil.insert(sendItem, out out_log); //LogUtil.log_call(this, "-----------out_log----------" + out_log); } //FollowUtil.load_call(cmsForm); } } }
/// <summary> /// 创建预览项 /// </summary> protected void GenerateSendItems() { // 生成每一项 _sendItems = new List <SendItem>(); List <ReceiveBox> receiveBoxes = new List <ReceiveBox>(); // 先从选择中获取收件人,如果没有选择,再从excel表中获取收件人 if (Receivers != null && Receivers.Count > 0) { receiveBoxes = TraverseReciveBoxes(Receivers); } else if (Data != null && Data.Count > 0) { // 从数据中获取收件人 foreach (JToken jt in Data) { string userName = jt.Value <string>(Fields.userName); if (string.IsNullOrEmpty(userName)) { continue; } // 从数据库中查找 var receiver = LiteDb.FirstOrDefault <ReceiveBox>(r => r.userName == userName); if (receiver != null) { receiveBoxes.Add(receiver); } } } // 获取全局的抄送人 List <ReceiveBox> copyToBoxes = TraverseReciveBoxes(CopyTo); var copyToEmails = copyToBoxes.ConvertAll(cb => cb.email); // 开始添加 foreach (var re in receiveBoxes) { var item = new SendItem() { receiverName = re.userName, receiverEmail = re.email, }; string sendHtml = Template.html; string subjectTemp = Subject; // 处理模板数据 // 判断有没有数据 JObject itemObj = new JObject(); if (Data != null && Data.Count > 0) { if (Data.FirstOrDefault(jt => jt.Value <string>(Fields.userName) == re.userName) is JObject itemDataTemp) { itemObj = itemDataTemp; } } // 添加默认用户名 if (!itemObj.ContainsKey(Fields.userName)) { itemObj.Add(new JProperty(Fields.userName, re.userName)); } // 添加收件箱 if (!itemObj.ContainsKey(Fields.inbox)) { itemObj.Add(new JProperty(Fields.inbox, re.email)); } // 获取数据 List <string> keys = itemObj.Properties().ToList().ConvertAll(p => p.Name); // 自定义内容优先于自定义模板 // 判断是否有自定义内容 if (keys.Contains(Fields.body)) { // 获取 body 值 string body = itemObj.Value <string>(Fields.body); if (!string.IsNullOrEmpty(body)) { sendHtml = body; } } // 添加自定义模板 // 判断是否有自定义模板 else if (keys.Contains(Fields.template)) { string customTemplateName = itemObj.Value <string>(Fields.template); if (!string.IsNullOrEmpty(customTemplateName)) { // 获取新模板,如果失败,则跳过,不发送 var customTemplate = LiteDb.SingleOrDefault <Template>(t => t.name == customTemplateName); if (customTemplate != null) { sendHtml = customTemplate.html; } } } // 添加附件 // 判断是否有自定义附件 item.attachments = Attachments; if (keys.Contains(Fields.attachments)) { // 中间用分号分隔,然后将 \\ 转成 / string attStr = itemObj.Value <string>(Fields.attachments); if (!string.IsNullOrEmpty(attStr)) { var attStrArr = attStr.Split(';'); item.attachments = attStrArr.ToList().ConvertAll(att => { var fullName = att.Replace('\\', '/').Trim(); return(new EmailAttachment() { fullName = fullName }); }); } } // 添加抄送人 // 判断是否有自定义抄送人 item.copyToEmails = copyToEmails; if (keys.Contains(Fields.copyToEmails)) { // 中间用分号分隔 string attStr = itemObj.Value <string>(Fields.copyToEmails); // 判断是否是邮箱的正则表达式 var regex = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"); if (!string.IsNullOrEmpty(attStr)) { var attStrArr = attStr.Split(';'); item.copyToEmails = attStrArr.ToList().ConvertAll(att => att.Trim()).FindAll(att => { return(regex.IsMatch(att)); }); } } // 替换模板内数据 foreach (string key in keys) { var regex = new Regex("{{\\s*" + key + "\\s*}}"); sendHtml = regex.Replace(sendHtml, itemObj[key].Value <string>()); // 同时替换主题数据 subjectTemp = regex.Replace(subjectTemp, itemObj[key].Value <string>()); } item.html = sendHtml; item.subject = subjectTemp; // 添加到保存的集合中 _sendItems.Add(item); } ; // 添加序号 for (int i = 0; i < _sendItems.Count; i++) { _sendItems[i].index = i; _sendItems[i].total = _sendItems.Count; } PreviewItemCreated(_sendItems, receiveBoxes); }
/// <summary> /// /// </summary> /// <param name="item"></param> private void AddSendItemToContextMenu(SendItem item, int no) { string s = string.Format( "{0}: {1}", GetNoMenuText(no), item.Name); ToolStripMenuItem menuitem = new ToolStripMenuItem(s); menuitem.Tag = item; menuitem.Click += new EventHandler(menuitem_Click); this.contextMenuStrip1.Items.Add (menuitem); }