private void btnTestEmail_Click(object sender, EventArgs e) { //using (EmailHelper Email = new EmailHelper()) //{ EmailHelper Email = new EmailHelper(); Email.To = "*****@*****.**"; Email.Subject = "Test"; //Email.AddAttachment(@"\\compaq1600\SystemReport\WIP - SubCon\WIP_SubCon_2014_06_06.xls"); Email.AddAttachment(@"C:\1020.log"); Email.SendEmail(); // } }
private void EmailReport(string ReportPath) { Logger.For(this).Info("开始"); Excel.Application xlApp = new Excel.Application(); xlApp.Caption = "NWMMS - WIP " + DateTime.Now.ToLongTimeString(); try { Excel.Workbook xlWb = ExcelHelper.OpenWB(xlApp, ReportPath, true); if (xlWb == null) { Logger.For(this).Error(string.Format("找不到报表 : {0}", ReportPath)); } else { if (string.IsNullOrEmpty(xlWb.BuiltinDocumentProperties["Category"].Value)) { using (EmailHelper Email = new EmailHelper()) { Email.Subject = string.Format("{0} - {1}", xlWb.BuiltinDocumentProperties["Subject"].Value.ToString(), DateTime.Today.ToString("yyyy-MM-dd")); Email.To = xlWb.BuiltinDocumentProperties["Manager"].Value.ToString(); if (xlWb.BuiltinDocumentProperties["Comments"].Value != null) Email.Body = xlWb.BuiltinDocumentProperties["Comments"].Value.ToString(); Email.AddAttachment(ReportPath); Email.SendEmail(); } } xlWb.Close(); xlWb = null; } } catch(Exception Ex) { Logger.For(this).Error(string.Format("报表 : {0}, 错误 : {1}", ReportPath, Ex.Message)); } xlApp.DisplayAlerts = true; ExcelHelper.KillExcelProcess(xlApp); Logger.For(this).Info("结束"); }
public bool SendEmail(string sBody, string sFilePath) { using (var eh = new EmailHelper(SmtpConnStr)) { eh.AddToAddress(EmailReceiver); eh.AddCcAddress(EmailCC); if (System.IO.File.Exists(sFilePath)) { eh.AddAttachment(new System.Net.Mail.Attachment(sFilePath)); } var dt = DateTime.Now; eh.Body = sBody; eh.Subject = MakeEmailSubject(dt); try { eh.SendMail(); } catch (Exception ex) { ErrorOut(ex); return(false); } } return(true); }
private void btnSendEmail_Click(object sender, EventArgs e) { EmailHelper email = new EmailHelper("smtp.163.com", "*****@*****.**", "wjm456852"); email.Subject = "伍华聪的普通测试邮件"; email.Body = string.Format("测试邮件正文内容"); email.IsHtml = true; email.From = "*****@*****.**"; email.FromName = "Jimmy"; email.AddRecipient("*****@*****.**"); try { bool success = email.SendEmail(); MessageDxUtil.ShowTips(success ? "发送成功" : "发送失败"); } catch (Exception ex) { LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(Form1)); MessageDxUtil.ShowError(ex.Message); } return; email = new EmailHelper("smtp.163.com", "*****@*****.**", "123abc"); email.Subject = "伍华聪的图片附件测试邮件"; string embedFile = Path.Combine(Application.StartupPath, "cityroad.jpg"); email.Body = string.Format("测试邮件正文内容<img src=\"{0}\" title='测试图片' /> <IMG src=\"C:\\Example.jpg\"> ", embedFile); email.IsHtml = true; email.From = "*****@*****.**"; email.FromName = "wuhuacong2013"; email.AddRecipient("*****@*****.**"); email.AddAttachment(Path.Combine(Application.StartupPath, "ringin.wav"));//.AddAttachment("C:\\test.txt"); try { bool success = email.SendEmail(); MessageDxUtil.ShowTips(success ? "发送成功" : "发送失败"); } catch (Exception ex) { LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(Form1)); MessageDxUtil.ShowError(ex.Message); } }
public ActionResult SendEmail(string id = "MA==") { if (TempData["openPopup"] != null) { ViewBag.openPopup = TempData["openPopup"]; } int Id = Convert.ToInt32(ConvertTo.Base64Decode(id)); if (Id > 0) { var model = abstractOpportunitiesServices.OpportunitiesSelectById(Id).Item; string Email = ProjectSession.Email; if (Email != "" && model != null) { string Emailtext = "<p style='margin-left: 70px;'>You can see #TASK# Details Below.</p><h5 style='margin-left: 70px;'> Opportunity Name :- <span style='font-weight:bold'>#OPNAME#</span></h5><h5 style='margin-left: 70px;'> Assigned User Name :- <span style='font-weight:bold'>#ASSIGNUSRNAME#</span></h5><h5 style='margin-left: 70px;'> Company Contact Name :- <span style='font-weight:bold'>#COMCONTNAME#</span></h5><h5 style='margin-left: 70px;'> Description :- <span style='font-weight:bold'>#Description#</span></h5><h5 style='margin-left: 70px;'> Status :- <span style='font-weight:bold'>#Status#</span></h5><h5 style='margin-left: 70px;'> Start Date :- <span style='font-weight:bold'>#StartDate#</span></h5><h5 style='margin-left: 70px;'> End Date :- <span style='font-weight:bold'>#EndDate#</span></h5><h5 style='margin-left: 70px;'> Success Rate Percent :- <span style='font-weight:bold'>#SuccessRatePercent#</span></h5>"; string body = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate/index.html"))) { body = reader.ReadToEnd(); } Emailtext = Emailtext.Replace("#TASK#", "Opportunity"); Emailtext = Emailtext.Replace("#OPNAME#", model.Name); Emailtext = Emailtext.Replace("#ASSIGNUSRNAME#", model.AssignedUserName); Emailtext = Emailtext.Replace("#COMCONTNAME#", model.CompanyContactName); Emailtext = Emailtext.Replace("#Description#", model.Description); Emailtext = Emailtext.Replace("#Status#", model.StatusName); Emailtext = Emailtext.Replace("#StartDate#", model.StartDate); Emailtext = Emailtext.Replace("#EndDate#", model.EndDate); Emailtext = Emailtext.Replace("#SuccessRatePercent#", Convert.ToString(model.SuccessRatePercent)); body = body.Replace("#TASK#", "Opportunity"); body = body.Replace("#USERNAME#", ProjectSession.UserName); body = body.Replace("#MAINMESSAGE#", Emailtext); //EmailHelper.Send(Email, "", "", "CRM Opportunity: " + model.Name, body); System.Net.Mail.Attachment Attachment1 = EmailHelper.AddAttachment("CRM Opportunity: " + model.Name, Emailtext, model.StartDate, model.EndDate); EmailHelper.Send1(Email, "", "", "CRM Opportunity: " + model.Name, body, Attachment1); } } return(RedirectToAction(Actions.Index, Pages.Controllers.Opportunities)); }