You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

301 lines
11 KiB

  1. using Learun.Application.OA.Email;
  2. using Learun.Application.OA.Email.EmailConfig;
  3. using Learun.Application.OA.Email.EmailReceive;
  4. using Learun.Application.OA.Email.EmailSend;
  5. using Learun.Util;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Web.Mvc;
  9. namespace Learun.Application.Web.Areas.LR_OAModule.Controllers
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  13. /// Copyright (c) 2013-2017
  14. /// 创建人:陈彬彬
  15. /// 日 期:2018.06.04
  16. /// 描 述:邮件管理
  17. /// </summary>
  18. public class EmailController : MvcControllerBase
  19. {
  20. private EmailIBLL emailIBLL = new EmailBLL();
  21. private EmailConfigIBLL emailConfigIBLL = new EmailConfigBLL();
  22. private EmailReceiveIBLL emailReceiveIBLL = new EmailReceiveBLL();
  23. private EmailSendIBLL emailSendIBLL = new EmailSendBLL();
  24. #region 视图功能
  25. /// <summary>
  26. /// 管理页面
  27. /// </summary>
  28. /// <returns></returns>
  29. [HttpGet]
  30. public ActionResult Index()
  31. {
  32. return View();
  33. }
  34. /// <summary>
  35. /// 写邮件
  36. /// </summary>
  37. /// <returns></returns>
  38. [HttpGet]
  39. public ActionResult Form()
  40. {
  41. return View();
  42. }
  43. /// <summary>
  44. /// 收件详情
  45. /// </summary>
  46. /// <returns></returns>
  47. [HttpGet]
  48. public ActionResult DetailForm()
  49. {
  50. return View();
  51. }
  52. /// <summary>
  53. /// 配置信息
  54. /// </summary>
  55. /// <returns></returns>
  56. [HttpGet]
  57. public ActionResult ConfigForm()
  58. {
  59. return View();
  60. }
  61. #endregion
  62. #region 获取数据
  63. /// <summary>
  64. /// 获取发送邮件数据
  65. /// </summary>
  66. /// <param name="pagination">分页参数</param>
  67. /// <param name="queryJson">关键词</param>
  68. /// <returns></returns>
  69. public ActionResult GetSendList(string pagination, string queryJson)
  70. {
  71. Pagination paginationobj = pagination.ToObject<Pagination>();
  72. var data = emailSendIBLL.GetSendList(paginationobj, queryJson);
  73. var jsonData = new
  74. {
  75. rows = data,
  76. total = paginationobj.total,
  77. page = paginationobj.page,
  78. records = paginationobj.records,
  79. };
  80. return JsonResult(jsonData);
  81. }
  82. /// <summary>
  83. /// 获取收取邮件数据
  84. /// </summary>
  85. /// <param name="pagination">分页参数</param>
  86. /// <param name="queryJson">关键词</param>
  87. /// <returns></returns>
  88. public ActionResult GetReceiveList(string pagination, string queryJson)
  89. {
  90. Pagination paginationobj = pagination.ToObject<Pagination>();
  91. var data = emailReceiveIBLL.GetReceiveList(paginationobj, queryJson);
  92. var jsonData = new
  93. {
  94. rows = data,
  95. total = paginationobj.total,
  96. page = paginationobj.page,
  97. records = paginationobj.records,
  98. };
  99. return JsonResult(jsonData);
  100. }
  101. /// <summary>
  102. /// 获取配置信息
  103. /// </summary>
  104. /// <param name="queryJson">关键词</param>
  105. /// <returns></returns>
  106. public ActionResult GetConfigList(string queryJson)
  107. {
  108. var data = emailConfigIBLL.GetConfigList(queryJson);
  109. return JsonResult(data);
  110. }
  111. /// <summary>
  112. /// 获取邮件发送实体
  113. /// </summary>
  114. /// <param name="keyValue">主键</param>
  115. /// <returns></returns>
  116. public ActionResult GetSendEntity(string keyValue)
  117. {
  118. var data = emailSendIBLL.GetSendEntity(keyValue);
  119. return JsonResult(data);
  120. }
  121. /// <summary>
  122. /// 获取邮件接收实体
  123. /// </summary>
  124. /// <param name="keyValue">主键</param>
  125. /// <returns></returns>
  126. public ActionResult GetReceiveEntity(string keyValue)
  127. {
  128. var data = emailReceiveIBLL.GetReceiveEntity(keyValue);
  129. return JsonResult(data);
  130. }
  131. /// <summary>
  132. /// 获取邮件配置实体
  133. /// </summary>
  134. /// <param name="keyValue">主键</param>
  135. /// <returns></returns>
  136. public ActionResult GetConfigEntity(string keyValue)
  137. {
  138. var data = emailConfigIBLL.GetConfigEntity(keyValue);
  139. return JsonResult(data);
  140. }
  141. /// <summary>
  142. /// 获取邮件
  143. /// </summary>
  144. /// <param name="receiveCount">主键</param>
  145. /// <returns></returns>
  146. public ActionResult GetMail()
  147. {
  148. EmailConfigEntity entity = emailConfigIBLL.GetCurrentConfig();
  149. MailAccount account = new MailAccount();
  150. account.POP3Host = entity.F_POP3Host;
  151. account.POP3Port = entity.F_POP3Port.ToInt();
  152. account.SMTPHost = entity.F_SMTPHost;
  153. account.SMTPPort = entity.F_SMTPPort.ToInt();
  154. account.Account = entity.F_Account;
  155. account.AccountName = entity.F_SenderName;
  156. account.Password = entity.F_Password;
  157. account.Ssl = entity.F_Ssl == 1 ? true : false;
  158. var receiveCount = emailReceiveIBLL.GetCount();
  159. List<MailModel> data = emailIBLL.GetMail(account, receiveCount);
  160. for (var i = 0; i < data.Count; i++)
  161. {
  162. EmailReceiveEntity receiveEntity = new EmailReceiveEntity();
  163. receiveEntity.F_Sender = data[i].To;
  164. receiveEntity.F_SenderName = data[i].ToName;
  165. receiveEntity.F_MID = data[i].UID;
  166. receiveEntity.F_Subject = data[i].Subject;
  167. receiveEntity.F_BodyText = data[i].BodyText;
  168. //receiveEntity.Attachment = data[i].Attachment;
  169. receiveEntity.F_Date = data[i].Date;
  170. emailReceiveIBLL.SaveReceiveEntity("", receiveEntity);
  171. }
  172. return JsonResult(data);
  173. }
  174. /// <summary>
  175. /// 发送邮件
  176. /// </summary>
  177. /// <param name="receiveCount">主键</param>
  178. /// <returns></returns>
  179. public ActionResult SendMail(EmailSendEntity entity)
  180. {
  181. EmailConfigEntity configEntity = emailConfigIBLL.GetCurrentConfig();
  182. MailAccount account = new MailAccount();
  183. account.POP3Host = configEntity.F_POP3Host;
  184. account.POP3Port = configEntity.F_POP3Port.ToInt();
  185. account.SMTPHost = configEntity.F_SMTPHost;
  186. account.SMTPPort = configEntity.F_SMTPPort.ToInt();
  187. account.Account = configEntity.F_Account;
  188. account.AccountName = configEntity.F_SenderName;
  189. account.Password = configEntity.F_Password;
  190. account.Ssl = configEntity.F_Ssl == 1 ? true : false;
  191. MailModel model = new MailModel();
  192. model.UID = Guid.NewGuid().ToString();
  193. entity.F_Id = model.UID;
  194. model.To = entity.F_To;
  195. //model.ToName = entity.F_To;
  196. model.CC = entity.F_CC;
  197. //model.CCName = entity.F_CC;
  198. model.Bcc = entity.F_BCC;
  199. //model.BccName = entity.F_BCC;
  200. model.Subject = entity.F_Subject;
  201. model.BodyText = entity.F_BodyText;
  202. //model.Attachment = entity.F_Attachment;
  203. model.Date = entity.F_Date.ToDate();
  204. emailIBLL.SendMail(account, model);
  205. entity.F_Sender = configEntity.F_Account;
  206. entity.F_SenderName = configEntity.F_SenderName;
  207. emailSendIBLL.SaveSendEntity("", entity);
  208. return Success("发送成功");
  209. }
  210. #endregion
  211. #region 提交数据
  212. /// <summary>
  213. /// 保存(新增、修改)
  214. /// </summary>
  215. /// <param name="keyValue">主键值</param>
  216. /// <param name="sendEntity">邮件发送实体</param>
  217. /// <returns></returns>
  218. [HttpPost, ValidateAntiForgeryToken, AjaxOnly, ValidateInput(false)]
  219. public ActionResult SaveSendEntity(string keyValue, EmailSendEntity sendEntity)
  220. {
  221. emailSendIBLL.SaveSendEntity(keyValue, sendEntity);
  222. return Success("保存成功!");
  223. }
  224. /// <summary>
  225. /// 保存(新增、修改)
  226. /// </summary>
  227. /// <param name="keyValue">主键值</param>
  228. /// <param name="receiveEntity">邮件接收实体</param>
  229. /// <returns></returns>
  230. [HttpPost, ValidateAntiForgeryToken, AjaxOnly, ValidateInput(false)]
  231. public ActionResult SaveReceiveEntity(string keyValue, EmailReceiveEntity receiveEntity)
  232. {
  233. emailReceiveIBLL.SaveReceiveEntity(keyValue, receiveEntity);
  234. return Success("保存成功!");
  235. }
  236. /// <summary>
  237. /// 保存(新增、修改)
  238. /// </summary>
  239. /// <param name="keyValue">主键值</param>
  240. /// <param name="configEntity">邮件配置实体</param>
  241. /// <returns></returns>
  242. [HttpPost, ValidateAntiForgeryToken, AjaxOnly, ValidateInput(false)]
  243. public ActionResult SaveConfigEntity(string keyValue, EmailConfigEntity configEntity)
  244. {
  245. emailConfigIBLL.SaveConfigEntity(keyValue, configEntity);
  246. return Success("保存成功!");
  247. }
  248. /// <summary>
  249. /// 删除表单数据
  250. /// </summary>
  251. /// <param name="keyValue">主键</param>
  252. /// <returns></returns>
  253. [HttpPost]
  254. [AjaxOnly]
  255. public ActionResult DeleteForm(string keyValue, string type)
  256. {
  257. EmailConfigEntity configEntity = emailConfigIBLL.GetCurrentConfig();
  258. MailAccount account = new MailAccount();
  259. account.POP3Host = configEntity.F_POP3Host;
  260. account.POP3Port = configEntity.F_POP3Port.ToInt();
  261. account.SMTPHost = configEntity.F_SMTPHost;
  262. account.SMTPPort = configEntity.F_SMTPPort.ToInt();
  263. account.Account = configEntity.F_Account;
  264. account.AccountName = configEntity.F_SenderName;
  265. account.Password = configEntity.F_Password;
  266. account.Ssl = configEntity.F_Ssl == 1 ? true : false;
  267. if (type == "1")
  268. {
  269. //emailIBLL.DeleteMail(account, keyValue);
  270. emailSendIBLL.DeleteEntity(keyValue);
  271. }
  272. else
  273. {
  274. var entity = emailReceiveIBLL.GetReceiveEntity(keyValue);
  275. emailIBLL.DeleteMail(account, entity.F_MID);
  276. emailReceiveIBLL.DeleteEntity(keyValue);
  277. }
  278. return Success("删除成功!");
  279. }
  280. #endregion
  281. }
  282. }