public void SendEmail(CodeActivityContext context, MemoryStream AttachContent) { MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(From.Get(context)); string STo = To.Get(context); STo.Split(new Char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList() .ForEach(item => mailMessage.To.Add(item.Trim())); mailMessage.Subject = Subject.Get(context); mailMessage.Body = Body.Get(context); SmtpClient smtpClient = new SmtpClient(); smtpClient.Host = Host.Get(context); smtpClient.Port = Port; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; if (!String.IsNullOrEmpty(UserName.Get(context)) && !String.IsNullOrEmpty(Password.Get(context))) { smtpClient.Credentials = new System.Net.NetworkCredential(UserName.Get(context), Password.Get(context)); } if (AttachContent != null) { string attachName = AttachName.Get(context); if (string.IsNullOrEmpty(attachName)) { attachName = "Отчет"; } else { attachName = ReportTools.CorrectFileName(attachName); } Attachment Attach; //if (UseZipArchive) //{ // MemoryStream compresStream = new MemoryStream(); // ComponentAce.Compression.ZipForge.ZipForge zip = new ComponentAce.Compression.ZipForge.ZipForge(); // zip.FileName = attachName + ".zip"; ; // AttachContent.Position = 0; // zip.OpenArchive(compresStream, true); // zip.AddFromStream(attachName + GetFileExtByReportFormat(), AttachContent); // zip.CloseArchive(); // Attach = new Attachment(AttachContent, zip.FileName); // zip.Dispose(); //} //else { Attach = new Attachment(AttachContent, attachName + GetFileExt()); } mailMessage.Attachments.Add(Attach); } //throw new Exception("Error sending email"); // test exception smtpClient.Send(mailMessage); }
public void PutReportToFolder(CodeActivityContext context, MemoryStream Document) { string folder; string fileName; folder = context.GetValue(this.Folder); fileName = context.GetValue(this.FileName); fileName = ReportTools.CorrectFileName(fileName + GetFileExtByReportFormat()); fileName = Path.Combine(folder, fileName); using (FileStream file = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { Document.WriteTo(file); } }