/// <summary> /// 发送邮件 /// </summary> public static void SendEmail() { var emailServiceBusiness = new Business.Services.EmailService.EmailBusiness(); var email = emailServiceBusiness.GetTodayData(); var emailFactory = new EmailFactory("*****@*****.**", "*****@*****.**"); var stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"进来简历总量:{email.ResumeCount}"); stringBuilder.AppendLine($"投递进来简历量:{email.DeliverCount}"); stringBuilder.AppendLine($"Cookie 进来简历量:{email.ResumeCount - email.DeliverCount}"); stringBuilder.AppendLine($"无Json源简历量:{email.NoJsonCount }"); stringBuilder.AppendLine($"上传简历量:{email.UploadCount}"); stringBuilder.AppendLine($"简历新增量:{email.CreateCount}"); stringBuilder.AppendLine($"简历更新量:{email.UpdateCount}"); stringBuilder.AppendLine($"简历剩余量:{email.SurplusCount}"); stringBuilder.AppendLine($"本周平均新增量:{email.AvgCreateCount}"); emailFactory.Body = stringBuilder.ToString(); emailFactory.IsBodyHtml = false; emailFactory.Subject = $"{DateTime.Now.AddDays(-1):yyyy-MM-dd} 每日数据指标统计(龙志杰)"; emailFactory.Send(); }
private bool sendForgotPasswordEmail(ApplicationUser user, string code) { try { string baseUrl = Request.Url.Authority; // For dev if (Request.Url.Authority.Contains("localhost")) { baseUrl = "http://vps232338.ovh.net"; } string callbackUrl = baseUrl + "/Angular/index.html#change_password" + "?userid=" + user.Id + "&code=" + code; EmailFactory factory = new EmailFactory(); MailMessage message = new MailMessage(); message.To.Add(new MailAddress(user.Email)); message.IsBodyHtml = true; if (HostingEnvironment.MapPath("~/Angular/email_templates/email_forgot_password.html") != null) { message.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath("~/Angular/email_templates/email_forgot_password.html")); } //Dev mode else { message.Body = System.IO.File.ReadAllText(@"D:\Travail\Reta\RetaTrunk\Reta\Reta\Angular\email_templates\email_forgot_password.html"); } // embed logo if exist string path = getPathToLogoForUser(user); if (!string.IsNullOrEmpty(path)) { Attachment inlineLogo = new Attachment(path); message.Attachments.Add(inlineLogo); string contentID = "Logo"; inlineLogo.ContentId = contentID; //To make the image display as inline and not as attachment inlineLogo.ContentDisposition.Inline = true; inlineLogo.ContentDisposition.DispositionType = DispositionTypeNames.Inline; string urlToTemplateFile = "cid:" + contentID; message.Body = message.Body.Replace("##urlToTemplateFolder##", urlToTemplateFile); } else { message.Body = message.Body.Replace("##urlToTemplateFolder##", ""); } message.Body = message.Body.Replace("##urlToConfirmPage##", callbackUrl); message.Subject = "Forgot Password"; message.From = new MailAddress(ConfigurationManager.AppSettings["ForgotPassword:Email:DefaultFrom"]); factory.Send(message); logger.Info("Forgot password sent to : " + user.Email); return(true); } catch (Exception ex) { logger.Error(ex.Message); return(false); } }
private void Send(JArray jArray) { var count = 0; foreach (var recipient in jArray) { var emailFactory = new EmailFactory((string)recipient["email"]); var body = (string)recipient["name"]; var ascii = (int)Convert.ToChar(body.Substring(0, 1).ToLower()); if (ascii < 97 || ascii > 122) { body = body.Substring(0, 1); } emailFactory.Body = $"{body} {this.tbx_Body.Text}"; emailFactory.Subject = this.tbx_Subject.Text; emailFactory.IsBodyHtml = false; if (this.lbl_Annex.Text != "未选择附件...") { emailFactory.Attachments(this.lbl_Annex.Text); } try { emailFactory.Send(); RunInMainthread(() => { Program.SetLog(this.tbx_Schedule, $"发送成功!{(string)recipient["email"]} {++count} / {jArray.Count}"); }); } catch (Exception ex) { RunInMainthread(() => { Program.SetLog(this.tbx_Schedule, $"发送失败!{ex.Message} {(string)recipient["email"]} {++count} / {jArray.Count}"); }); } } }
public string Send(string value) { EmailToSend emailToSend = JsonConvert.DeserializeObject <EmailToSend>(value); MySqlIdentityDbContext db = new MySqlIdentityDbContext(); var files = Request.Files; string result = ""; if (User == null || !User.Identity.IsAuthenticated) { return(""); } var claims = UserManager.GetClaims(User.Identity.GetUserId()); EmailFactory factory = new EmailFactory(claims); int j = 0; foreach (string sendTo in emailToSend.SendTo) { try { var message = factory.GetTemplate(emailToSend.Template, sendTo); Object obj = new Object(); /*/ * if (emailToSend.Type == "candidat") * { * obj = db.Candidats.Where(a => a.Email == sendTo).FirstOrDefault(); * } * else if (emailToSend.Type == "customer") * { * obj = db.Customers.Where(a => a.Email == sendTo).FirstOrDefault(); * } * else if (emailToSend.Type == "linkedin") * { * obj = db.ContactLinkedins.Where(a => a.Email == sendTo).FirstOrDefault(); * } * else * { * result = result + "<tr><td>" + sendTo + "</td><td><b> Type d'objet non spécifié </b> </td></tr>"; * continue; * }/*/ // ajout des pièces jointe si elles existent if (files.Count > 0) { for (int i = 0; i < files.Count; i++) { message.Attachments.Add(new System.Net.Mail.Attachment(files[i].InputStream, files[i].FileName)); } } // Envoyer l'email à l'administrateur et à l'utilisateur qui envoie if (j == 0) { try { message.To.Clear(); message.To.Add(new MailAddress(User.Identity.Name)); factory.Send(factory.ReplaceVariableInTemplate(message, obj)); logger.Info(" Email copy sent to : " + User.Identity.Name); if (ConfigurationManager.AppSettings["SmtpServer:AllEmailCciTo"] != User.Identity.Name) { message.To.Clear(); message.To.Add(new MailAddress(ConfigurationManager.AppSettings["SmtpServer:AllEmailCciTo"])); factory.Send(factory.ReplaceVariableInTemplate(message, obj)); logger.Info(" Email copy sent to : " + ConfigurationManager.AppSettings["SmtpServer:AllEmailCciTo"]); } if (ConfigurationManager.AppSettings["SmtpServer:AllEmailCciTo2"] != User.Identity.Name) { message.To.Clear(); message.To.Add(new MailAddress(ConfigurationManager.AppSettings["SmtpServer:AllEmailCciTo2"])); factory.Send(factory.ReplaceVariableInTemplate(message, obj)); logger.Info(" Email copy sent to : " + ConfigurationManager.AppSettings["SmtpServer:AllEmailCciTo2"]); } } catch (Exception ex) { logger.Error(" Error in sending Cci email - " + ex.Message); } message.To.Clear(); message.To.Add(new MailAddress(sendTo)); } factory.Send(factory.ReplaceVariableInTemplate(message, obj)); result = result + "<tr><td>" + sendTo + "</td><td><b> Envoyé </b> </td></tr>"; logger.Info(" Email copy sent to : " + sendTo); j++; } catch (Exception ex) { result = result + "<tr><td>" + sendTo + "</td><td><b> Non envoyé</b> </td></tr>"; logger.Error(ex.Message); } } return(result); }