protected override List <Email> AdapterOut(params Email[] entities) { foreach (var item in entities) { item.Attachments = AttachmentsIO.getAttachmentsFromFolder(item.AttachmentsFolder, "EmailAttachments"); } return(entities.ToList()); }
public override List <MdcAttachmentFile> AdapterOut(params MdcAttachmentFile[] entities) { foreach (var item in entities) { item.Attachments = AttachmentsIO.getAttachmentsFromFolder(item.AttachmentsFolder, "MdcAttachment"); } return(entities.ToList()); }
public void SendMail() { var request = new RestRequest(); request.Method = Method.POST; request.AddParameter("from", From); foreach (var to in To) { request.AddParameter("to", to); } foreach (var cc in Cc) { request.AddParameter("cc", cc); } foreach (var bcc in Bcc) { request.AddParameter("bcc", bcc); } request.AddParameter("subject", Subject); string baseAttachmentsPath = AppSettings.Get <string>("EmailAttachments"); var attachments = AttachmentsIO.getAttachmentsFromFolder(AttachmentsFolder, "EmailAttachments"); foreach (var attachment in attachments) { string filePath = baseAttachmentsPath + attachment.Directory + "\\" + attachment.FileName; request.AddFile("attachment", filePath); } if (!string.IsNullOrWhiteSpace(Template)) { request.AddParameter("template", Template); foreach (var param in TemplateParameters) { request.AddParameter($"v:{param.Key}", param.Value); } } else { request.AddParameter("html", Body); } var response = Client.Execute(request); var content = response.Content; if (!response.IsSuccessful) { throw new Exception(content); } }
protected override void AdapterOut(params PurchaseRequest[] entities) { var ctx = context as POContext; foreach (var item in entities) { //item.PRNumber = ctx.PRNumbers.FirstOrDefault(e => e.PRNumberKey == item.PRNumberKey); item.PRLines = item.PRLines?.OrderBy(e => e.PRLineKey).ToList(); item.Attachments = AttachmentsIO.getAttachmentsFromFolder(item.AttachmentsFolder, "PR_Attachments"); } }
public void SendMail() { try { smtp.EnableSsl = true; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential(From, FromPassword); MailMessage message = new MailMessage(); message.From = new MailAddress(From, From); foreach (var to in To) { message.To.Add(new MailAddress(to)); } foreach (var cc in Cc) { message.CC.Add(new MailAddress(cc)); } foreach (var bcc in Bcc) { message.Bcc.Add(new MailAddress(bcc)); } message.Subject = Subject; message.IsBodyHtml = true; message.BodyEncoding = System.Text.Encoding.UTF8; message.Body = Body; string baseAttachmentsPath = AppSettings.Get <string>("EmailAttachments"); var attachments = AttachmentsIO.getAttachmentsFromFolder(AttachmentsFolder, "EmailAttachments"); foreach (var attachment in attachments) { string filePath = baseAttachmentsPath + attachment.Directory + "\\" + attachment.FileName; FileInfo file = new FileInfo(filePath); message.Attachments.Add(new System.Net.Mail.Attachment(new FileStream(filePath, FileMode.Open, FileAccess.Read), attachment.FileName)); } smtp.Send(message); } catch (System.Exception ex) { throw ex; } }
public object Post(PostAttachment request) { var response = new CommonResponse(); string attachmentKind = request.AttachmentKind; if (attachmentKind == null || attachmentKind == "") { response.ErrorThrown = true; response.ResponseDescription = "Attachment Kind was not specified."; return(response); } if (Request.Files.Length == 0) { throw new HttpError(HttpStatusCode.BadRequest, "NoFile"); } var postedFile = Request.Files[0]; string fileName = postedFile.FileName; string baseAttachmentsPath = AppSettings.Get <string>(attachmentKind); bool useAttachmentsRelativePath = false; string sUseAttachmentsRelativePath = AppSettings.Get <string>("UseAttachmentsRelativePath"); if (!string.IsNullOrWhiteSpace(sUseAttachmentsRelativePath) && bool.TryParse(sUseAttachmentsRelativePath, out bool bUseAttachmentsRelativePath)) { useAttachmentsRelativePath = bUseAttachmentsRelativePath; } string currentPathAttachments; string folderName = request.TargetFolder; if (!string.IsNullOrWhiteSpace(folderName)) { if (useAttachmentsRelativePath) { currentPathAttachments = "~/" + baseAttachmentsPath + folderName + @"/".MapHostAbsolutePath(); } else { currentPathAttachments = baseAttachmentsPath + folderName + @"\"; } if (!Directory.Exists(currentPathAttachments)) { Directory.CreateDirectory(currentPathAttachments); } } else { string folderPrefix = request.FolderPrefix; if (string.IsNullOrWhiteSpace(folderPrefix) || folderPrefix == "undefined" || folderPrefix == "null") { folderPrefix = ""; } do { DateTime date = DateTime.Now; folderName = folderPrefix + date.ToString("yy") + date.Month.ToString("d2") + date.Day.ToString("d2") + "_" + MD5HashGenerator.GenerateKey(date); if (useAttachmentsRelativePath) { currentPathAttachments = "~/" + baseAttachmentsPath + folderName.MapHostAbsolutePath(); } else { currentPathAttachments = baseAttachmentsPath + folderName; } } while (Directory.Exists(currentPathAttachments)); Directory.CreateDirectory(currentPathAttachments); if (useAttachmentsRelativePath) { currentPathAttachments += @"/"; } else { currentPathAttachments += @"\"; } } if (postedFile.ContentLength > 0) { postedFile.SaveTo(currentPathAttachments + Path.GetFileName(postedFile.FileName)); } var attachmentsResult = AttachmentsIO.getAttachmentsFromFolder(folderName, attachmentKind); response.ErrorThrown = false; response.ResponseDescription = folderName; response.Result = attachmentsResult; return(response); }
public object attachmentsPost() { CommonResponse response = new CommonResponse(); try { if (HttpContext.Current.Request.Files.AllKeys.Any()) { var postedFile = HttpContext.Current.Request.Files["file"]; string attachmentKind = HttpContext.Current.Request["attachmentKind"]; if (attachmentKind == null || attachmentKind == "") { response.ErrorThrown = true; response.ResponseDescription = "Attachment Kind was not specified."; return(response); } if (postedFile != null) { string fileName = postedFile.FileName; string baseAttachmentsPath = ConfigurationManager.AppSettings[attachmentKind]; string currentPathAttachments; string folderName = HttpContext.Current.Request["targetFolder"]; if (folderName != null && folderName.Trim() != "") { currentPathAttachments = baseAttachmentsPath + folderName + @"\"; if (!Directory.Exists(currentPathAttachments)) { Directory.CreateDirectory(currentPathAttachments); } } else { do { DateTime date = DateTime.Now; folderName = date.ToString("yy") + date.Month.ToString("d2") + date.Day.ToString("d2") + "_" + MD5HashGenerator.GenerateKey(date); currentPathAttachments = baseAttachmentsPath + folderName; } while (Directory.Exists(currentPathAttachments)); Directory.CreateDirectory(currentPathAttachments); currentPathAttachments += @"\"; } if (postedFile.ContentLength > 0) { postedFile.SaveAs(currentPathAttachments + Path.GetFileName(postedFile.FileName)); } List <Attachment> attachmentsResult = AttachmentsIO.getAttachmentsFromFolder(folderName, attachmentKind); response.ErrorThrown = false; response.ResponseDescription = folderName; response.Result = attachmentsResult; } } } catch (Exception e) { response.ErrorThrown = true; response.ResponseDescription = "ERROR: " + e.Message; response.Result = e; } return(response); }
public object attachmentsPost() { CommonResponse response = new CommonResponse(); try { string attachmentKind = HttpContext.Current.Request["attachmentKind"]; if (attachmentKind == null || attachmentKind == "") { response.ErrorThrown = true; response.ResponseDescription = "Attachment Kind was not specified."; return(response); } var postedFile = HttpContext.Current.Request.Files["file"]; if (postedFile != null) { string fileName = postedFile.FileName; string baseAttachmentsPath = ConfigurationManager.AppSettings[attachmentKind]; bool useAttachmentsRelativePath = false; string sUseAttachmentsRelativePath = ConfigurationManager.AppSettings["UseAttachmentsRelativePath"]; if (!string.IsNullOrWhiteSpace(sUseAttachmentsRelativePath) && bool.TryParse(sUseAttachmentsRelativePath, out bool bUseAttachmentsRelativePath)) { useAttachmentsRelativePath = bUseAttachmentsRelativePath; } string currentPathAttachments; string folderName = HttpContext.Current.Request["targetFolder"]; if (folderName != null && folderName.Trim() != "") { if (useAttachmentsRelativePath) { currentPathAttachments = HostingEnvironment.MapPath("~/" + baseAttachmentsPath + folderName + @"/"); } else { currentPathAttachments = baseAttachmentsPath + folderName + @"\"; } if (!Directory.Exists(currentPathAttachments)) { Directory.CreateDirectory(currentPathAttachments); } } else { string folderPrefix = HttpContext.Current.Request["folderPrefix"]; if (string.IsNullOrWhiteSpace(folderPrefix) || folderPrefix == "undefined" || folderPrefix == "null") { folderPrefix = ""; } do { DateTime date = DateTime.Now; folderName = folderPrefix + date.ToString("yy") + date.Month.ToString("d2") + date.Day.ToString("d2") + "_" + MD5HashGenerator.GenerateKey(date); if (useAttachmentsRelativePath) { currentPathAttachments = HostingEnvironment.MapPath("~/" + baseAttachmentsPath + folderName); } else { currentPathAttachments = baseAttachmentsPath + folderName; } } while (Directory.Exists(currentPathAttachments)); Directory.CreateDirectory(currentPathAttachments); if (useAttachmentsRelativePath) { currentPathAttachments += @"/"; } else { currentPathAttachments += @"\"; } } if (postedFile.ContentLength > 0) { postedFile.SaveAs(currentPathAttachments + Path.GetFileName(postedFile.FileName)); } List <Attachment> attachmentsResult = AttachmentsIO.getAttachmentsFromFolder(folderName, attachmentKind); response.ErrorThrown = false; response.ResponseDescription = folderName; response.Result = attachmentsResult; } } catch (Exception e) { response.ErrorThrown = true; response.ResponseDescription = "ERROR: " + e.Message; response.Result = e; } return(response); }
public void SendMail() { try { From = AppSettings.Get <string>("smtp.from"); FromPassword = AppSettings.Get <string>("smtp.password"); var smtpServer = AppSettings.Get <string>("smtp.server"); var smtpPort = AppSettings.Get <string>("smtp.port"); var smtpSSL = AppSettings.Get("smtp.ssl", true); if (string.IsNullOrWhiteSpace(smtpServer) || string.IsNullOrWhiteSpace(smtpPort)) { return; } smtp = new SmtpClient(smtpServer, int.Parse(smtpPort)); smtp.EnableSsl = smtpSSL; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential(From, FromPassword); MailMessage message = new MailMessage(); message.From = new MailAddress(From, From); foreach (var to in To) { message.To.Add(new MailAddress(to)); } foreach (var cc in Cc) { message.CC.Add(new MailAddress(cc)); } foreach (var bcc in Bcc) { message.Bcc.Add(new MailAddress(bcc)); } message.Subject = Subject; message.IsBodyHtml = true; message.BodyEncoding = System.Text.Encoding.UTF8; message.Body = Body; string baseAttachmentsPath = AppSettings.Get <string>("EmailAttachments"); var attachments = AttachmentsIO.getAttachmentsFromFolder(AttachmentsFolder, "EmailAttachments"); foreach (var attachment in attachments) { string filePath = baseAttachmentsPath + attachment.Directory + "\\" + attachment.FileName; FileInfo file = new FileInfo(filePath); message.Attachments.Add(new System.Net.Mail.Attachment(new FileStream(filePath, FileMode.Open, FileAccess.Read), attachment.FileName)); } smtp.Send(message); Log.Info($"SMTP Email sent by: [{From}] to:[{To.Join(", ")}] cc:[{Cc.Join(", ")}] bcc:[{Bcc.Join(", ")}] subject: [{Subject}]"); } catch (System.Exception ex) { throw ex; } }