public bool SendMail(E_Mail entity, string fromID, string toID, string ccID, string isSend, bool remind) { //邮件相关人 List <E_Mail_Worker> mailWorker = GetMailWorker(entity, fromID, toID, ccID, isSend); //发送短信 if (isSend == "1" && remind == true) { bool send; List <string> TelList = DAL.Email.Email.GetTelList(mailWorker); string Content = GetStringNoHtml(entity.Body); send = SendMsg(TelList, Content); if (send) { return(DAL.Email.Email.SendMail(entity, mailWorker)); } else { return(false); } } return(DAL.Email.Email.SendMail(entity, mailWorker)); }
public bool SendMail(string title, string content, string toID, bool remind) { E_Mail mail = DAL.Email.Email.CreateMail(title, content, toID); //List<string> toStr = new List<string>(); //foreach (string r in toID.Split(',').ToList()) //{ // toStr.Add("Worker-" + r); //} //string toID_ = String.Join(",", toStr); //邮件相关人 List <E_Mail_Worker> mailWorker = GetMailWorker(mail, "0", toID, "", "1"); //发送短信 if (remind == true) { List <string> TelList = DAL.Email.Email.GetTelList(mailWorker); string Content = content; SendMsg(TelList, content); } return(DAL.Email.Email.SendMail(mail, mailWorker)); }
public static E_Mail CreateMail(string title, string content, string toID) { using (MainDataContext dbContext = new MainDataContext()) { E_Mail mail = new E_Mail(); //邮件主表 mail.ID = PrimaryKeyCreater.getIntPrimaryKey("E_Mail"); mail.From = "系统"; mail.Title = title; mail.Body = content; mail.CreateTime = DateTime.Now; mail.SendDate = DateTime.Now; List <string> toStr = new List <string>(); foreach (string r in toID.Split(',').ToList()) { int id = int.Parse(r); //人员ID string name = dbContext.B_WORKER.FirstOrDefault(b => b.ID == id).Name; toStr.Add(name); } mail.To = String.Join(",", toStr); return(mail); } }
public static void AddedEmailToForm(E_Mail mail, bool InputEmailInBrowser) { Main._Form1.Invoke(new Action(() => Main.email = mail)); Main._Form1.Invoke(new Action(() => Main._Form1.lbl_Email.Text = mail.EMAIL)); Main._Form1.Invoke(new Action(() => Main._Form1.btn_GetEmail.Enabled = true)); Main._Form1.Invoke(new Action(() => Main._Form1.btn_ConfirLink.Enabled = true)); if (InputEmailInBrowser) { Main.AddedEmail(mail.EMAIL); } }
[ValidateInput(false)] //当页面提交具有html标签时不进行验证 public ActionResult SendMail(E_Mail entity, string isSend) { BLL.Email.Email email = new BLL.Email.Email(); entity.SendDate = DateTime.Now; //发送时间 entity.Body = Request.Form["editor"]; //正文 string fromID = Request.Form["WriterID"]; //写信人ID string toID = Request.Form["toID"]; //收件人ID string ccID = Request.Form["ccID"]; //抄送人ID //string scID = Request.Form["scID"]; //密送人ID string remind = Request.Form["remind"]; bool remind_ = remind == null ? false : true; //判断是否发送短信 if (ModelState.IsValid) { bool send; try { send = email.SendMail(entity, fromID, toID, ccID, isSend, remind_); } catch (Exception) { send = false; } if (isSend == "1") { if (send) { return(Json(new { IsSuccess = true, Message = "发送成功" }, "text/html", JsonRequestBehavior.AllowGet)); } else { return(Json(new { IsSuccess = false, Message = "发送失败" }, "text/html", JsonRequestBehavior.AllowGet)); } } else { if (send) { return(Json(new { IsSuccess = true, Message = "保存成功" }, "text/html", JsonRequestBehavior.AllowGet)); } else { return(Json(new { IsSuccess = false, Message = "保存失败" }, "text/html", JsonRequestBehavior.AllowGet)); } } } return(View()); }
/// <summary> /// 发送&&存草稿 /// </summary> /// <param name="entity">邮件实体</param> /// <param name="mailWorker">邮件相关人</param> /// <returns></returns> public static bool SendMail(E_Mail entity, List <E_Mail_Worker> mailWorker) { using (MainDataContext dbContext = new MainDataContext()) { try { var email = dbContext.E_Mail.FirstOrDefault(m => m.ID == entity.ID); if (email == null) //新建信件 { //邮件主表 dbContext.E_Mail.InsertOnSubmit(entity); } else //从草稿箱进入 { //邮件主表 email.Title = entity.Title; email.SendDate = entity.SendDate; email.From = entity.From; email.Body = entity.Body; email.CC = entity.CC; email.CreateTime = entity.CreateTime; email.SC = entity.SC; email.To = entity.To; var list = dbContext.E_Mail_Worker.Where(m => m.MailId == entity.ID).ToList(); foreach (E_Mail_Worker m in list) { dbContext.E_Mail_Worker.DeleteOnSubmit(m); } } //存入数据库 foreach (E_Mail_Worker w in mailWorker) { dbContext.E_Mail_Worker.InsertOnSubmit(w); } dbContext.SubmitChanges(); return(true); } catch (Exception ex) { Log4Net.LogError("SendMail", ex.ToString()); return(false); } } }
public static void Get_Mail(int MaxAccInEmail) { int trycount = 0; string OldEmailChecked = ""; inicio: if (trycount >= 5) { Main._Form1.ShowMessageBox($"NO EMAIL AVAILABLE\r\n", "NO EMAIL AVAILABLE", MessageBoxButtons.OK, MessageBoxIcon.Information); AddedEmailToForm(new E_Mail { EMAIL = "NO EMAIL AVAILABLE" }, false); return; } var avaliableemails = Main.EMAIl_LIST.Where(a => a.LinkedAccounts < MaxAccInEmail).ToList(); if (avaliableemails.Count == 0) { MessageBox.Show($"No email available, all emails already have the maximum number of accounts => {MaxAccInEmail}", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Main._Form1.Invoke(new Action(() => Main._Form1.btn_GetEmail.Enabled = true)); return; } E_Mail mail = avaliableemails[RandomUtils.GetRandomInt(0, avaliableemails.Count)]; bool working = AccessEmailPop3Client.CheckEmailAccess(mail); if (working == true) { AddedEmailToForm(mail, true); Thread th = new Thread(() => Main.CheckConfirmEmailDialog()); th.IsBackground = true; th.Start(); } else { if (OldEmailChecked == mail.EMAIL) { trycount++; } OldEmailChecked = mail.EMAIL; goto inicio; } }
public static bool CheckEmailAccess(E_Mail mail) { string Pop3HostName = ""; var splittogetdomain = mail.EMAIL.Split('@'); string domainName = splittogetdomain[1]; var popconfig = Main.pop3s.Where(a => a.SuportedDomains.Contains(domainName)).FirstOrDefault(); if (popconfig != null) { Pop3HostName = popconfig.PoP3Server; } else { Log.error($"Pop3 HostName not defined for {domainName}"); return(false); } string username = mail.EMAIL, password = mail.PASS; using (var client = new Pop3Client()) { try { client.Connect(Pop3HostName, 995, true); client.Authenticate(username, password); if (client.IsAuthenticated == true) { return(true); } else { return(false); } } catch (Exception ex) { Log.error("Error to acess E-mail: " + username); Log.error(ex.Message); return(false); } } }
//public string SendMessages() //{ // ISender MMS = new MMS(); // ISender SMS = new SMS(); // ISender E_Mail = new E_Mail(); // return ; //} static void Main(string[] args) { //IPay payment = null; //string input = Console.ReadLine(); //switch (input) //{ // case "cash": // payment = new Cash(); // break; // case "card": // payment = new Card(); // break; // case "tr": // payment = new Transfer(); // break; // case "blik": // payment = new Blik(); // break; // default: // break; //} //try //{ // Console.WriteLine(payment.Payment(13)); //} //catch (Exception ex) //{ // Console.WriteLine(ex.Message); //} //Door door = new Door(); //var smart = door as IStandard; //Console.WriteLine(smart.Close()); //Console.WriteLine(((IStandard)door).Open()); ISender MMS = new MMS(); ISender SMS = new SMS(); ISender E_Mail = new E_Mail(); ISender Pigeon = new Pigeon(); Console.WriteLine($"Wysyłam widomość za pomocą: {MMS.Method()} {SMS.Method()} {E_Mail.Method()} {Pigeon.Method()}"); Console.Read(); }
// // GET: /Email/ #region 写信 public ActionResult Write(int?pageNumber, int?mailID, string type) { BLL.Email.Email email = new BLL.Email.Email(); this.ViewData["WriterID"] = User.Identity.Name.Split('|')[0]; this.ViewData["WriterName"] = User.Identity.Name.Split('|')[1]; //发信人 if (mailID != null) { if (type == "reply") //回复 { this.ViewData["MailID"] = PrimaryKeyCreater.getIntPrimaryKey("E_Mail"); //邮件编号 this.ViewData["CreateTime"] = DateTime.Now.AddDays(0).ToString("yyyy-MM-dd HH:mm:ss");; //创建时间 E_Mail mail = email.GetMailInfo((int)mailID); this.ViewData["To"] = mail.From; //收件人 this.ViewData["Title"] = "回复:" + mail.Title; //主题 this.ViewData["Body"] = "<br><hr>" + mail.Body; //内容 List <E_Mail_Worker> toWorker = email.GetMailWorker((int)mailID, 0); //收件人ID List <int> toStr = new List <int>(); foreach (E_Mail_Worker w in toWorker) { toStr.Add(w.WorkerId); } this.ViewData["toID"] = String.Join(",", toStr); } else if (type == "forward") //转发 { this.ViewData["MailID"] = PrimaryKeyCreater.getIntPrimaryKey("E_Mail"); //邮件编号 this.ViewData["CreateTime"] = DateTime.Now.AddDays(0).ToString("yyyy-MM-dd HH:mm:ss");; //创建时间 E_Mail mail = email.GetMailInfo((int)mailID); this.ViewData["Title"] = "转发:" + mail.Title; //主题 this.ViewData["Body"] = "<br><hr>" + mail.Body; //内容 } else //草稿 { this.ViewData["pageNumber"] = pageNumber; E_Mail mail = email.GetMailInfo((int)mailID); this.ViewData["MailID"] = mailID; //邮件编号 this.ViewData["CreateTime"] = mail.CreateTime; //创建时间 this.ViewData["To"] = mail.To; //收件人 this.ViewData["CC"] = mail.CC == null ? "" : mail.CC; //抄送 //this.ViewData["SC"] = mail.SC; //密送 this.ViewData["Title"] = mail.Title; //主题 this.ViewData["Body"] = mail.Body; //内容 List <E_Mail_Worker> toWorker = email.GetMailWorker((int)mailID, 1); //收件人ID List <int> toStr = new List <int>(); foreach (E_Mail_Worker w in toWorker) { toStr.Add(w.WorkerId); } this.ViewData["toID"] = String.Join(",", toStr); List <E_Mail_Worker> ccWorker = email.GetMailWorker((int)mailID, 2); //抄送人ID List <int> ccStr = new List <int>(); foreach (E_Mail_Worker w in ccWorker) { ccStr.Add(w.WorkerId); } this.ViewData["ccID"] = String.Join(",", ccStr); } } else { this.ViewData["MailID"] = PrimaryKeyCreater.getIntPrimaryKey("E_Mail"); //邮件编号 this.ViewData["CreateTime"] = DateTime.Now.AddDays(0).ToString("yyyy-MM-dd HH:mm:ss"); this.ViewData["toID"] = string.Empty; //收件人ID this.ViewData["To"] = string.Empty; //收件人 this.ViewData["CC"] = string.Empty; //抄送 this.ViewData["ccID"] = string.Empty; //抄送人ID this.ViewData["SC"] = string.Empty; //密送 this.ViewData["Title"] = string.Empty; //主题 this.ViewData["Body"] = string.Empty; //内容 } return(View()); }
/// <summary> /// 得到邮件相关人 /// </summary> /// <returns></returns> public List <E_Mail_Worker> GetMailWorker(E_Mail entity, string fromID, string toID, string ccID, string isSend) { List <E_Mail_Worker> mailWorker = new List <E_Mail_Worker>(); E_Mail_Worker mailS = new E_Mail_Worker(); //发件人(类型为0) mailS.ID = PrimaryKeyCreater.getIntPrimaryKey("E_Mail_Worker"); mailS.MailId = entity.ID; mailS.WorkerId = int.Parse(fromID); mailS.Type = 0; mailS.ReadFlag = "1"; //默认已读 if (isSend == "1") { mailS.FolderID = 3; //已发送 } else { mailS.FolderID = 2; //草稿箱 } mailWorker.Add(mailS); //收件人(类型为1) foreach (string r in toID.Split(',').ToList()) { E_Mail_Worker mailR = new E_Mail_Worker(); mailR.ID = PrimaryKeyCreater.getIntPrimaryKey("E_Mail_Worker"); mailR.MailId = entity.ID; mailR.WorkerId = int.Parse(r); mailR.Type = 1; mailR.ReadFlag = "0"; if (isSend == "1") { mailR.FolderID = 1; //收件箱 } else { mailR.FolderID = 5; //临时文件夹 } mailWorker.Add(mailR); } //抄送人(类型为2) if (!string.IsNullOrEmpty(ccID)) { foreach (string r in ccID.Split(',').ToList()) { E_Mail_Worker mailCC = new E_Mail_Worker(); mailCC.ID = PrimaryKeyCreater.getIntPrimaryKey("E_Mail_Worker"); mailCC.MailId = entity.ID; mailCC.WorkerId = int.Parse(r); mailCC.Type = 2; mailCC.ReadFlag = "0"; if (isSend == "1") { mailCC.FolderID = 1; //收件箱 } else { mailCC.FolderID = 5; //临时文件夹 } mailWorker.Add(mailCC); } } return(mailWorker); }
public static void Get_URL_Confirm(E_Mail mail) { int tentativas_get_code = 0; INICIO: string Confirm_Link = ""; string Pop3HostName = ""; var splittogetdomain = mail.EMAIL.Split('@'); string domainName = splittogetdomain[1]; var popconfig = Main.pop3s.Where(a => a.SuportedDomains.Contains(domainName)).FirstOrDefault(); if (popconfig != null) { Pop3HostName = popconfig.PoP3Server; } else { Log.error($"Pop3 HostName not defined for {domainName}"); return; } string username = mail.EMAIL, password = mail.PASS; using (var client = new Pop3Client()) { try { client.Connect(Pop3HostName, 995, true); client.Authenticate(username, password); if (client.IsAuthenticated == true) { Pop3Client = client; } } catch (Exception ex) { Log.error("Error to acess E-mail: " + username); Log.error(ex.Message); } while (Confirm_Link == "") { if (tentativas_get_code < 6) { try { var message1 = client.GetMessage(client.Count - 1); var creationid = new Regex("creationid=(\\d+)").Match(message1.HtmlBody.ToString()).Groups[1].Value; var stoken = new Regex("(?<=stoken\\=)\\w+").Match(message1.HtmlBody.ToString()).Value; bool ja_usado = CreationID_DB.Check_AlreadyUsed(creationid); if (ja_usado == true) { goto INICIO; } else { Confirm_Link = $"https://store.steampowered.com/account/newaccountverification?stoken={stoken}&creationid={creationid}"; var request = new RequestBuilder(Confirm_Link).GET().Execute(); Log.info($"Link Successfully Found..."); Main._Form1.Invoke(new Action(() => { //Main._Form1.btn_SaveAcc.Enabled = true; Main._Form1.btn_GenLoginPass.Enabled = true; })); Thread th = new Thread(() => Main.CheckExistingAccountOnEmail()); th.IsBackground = true; th.Start(); Thread th1 = new Thread(() => Main.GenLoginAndPassAutomatic()); th1.IsBackground = true; th1.Start(); lock (locker) { CreationID_DB.ADD_TO_DB(creationid); } } } catch { Log.error("Erro To get Confirm URL. Try Again!!"); Thread.Sleep(TimeSpan.FromSeconds(15)); tentativas_get_code = tentativas_get_code + 1; client.Disconnect(true); goto INICIO; } } else { Log.error("Erro To get Confirm URL From Email!"); } } client.Disconnect(true); } }