public static AttachmentsCollection GetAllPMProjectAttach(int CompanyID, string ProjectCD) { AttachmentsCollection collection = new AttachmentsCollection(); using (var reader = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "PMProjectAttach_GetAll", new SqlParameter[] { new SqlParameter("@ProjectCD", ProjectCD), new SqlParameter("@CompanyID", CompanyID), })) { while (reader.Read()) { Attachments objItem = new Attachments(); objItem.AttachID = SqlHelper.GetGuid(reader, "AttachID"); objItem.CompanyID = SqlHelper.GetInt(reader, "CompanyID"); objItem.Filetype = SqlHelper.GetString(reader, "Filetype"); objItem.Title = SqlHelper.GetString(reader, "Title"); objItem.Description = SqlHelper.GetString(reader, "Description"); objItem.Version = SqlHelper.GetString(reader, "Version"); collection.Add(objItem); } } return(collection); }
/// <summary> /// Carga los parámetros /// </summary> public void LoadParameters(AttachmentsCollection objColAttachments) { // Inicializa el control InitControl(); // Carga los parámetros foreach (Attachment objAttachment in objColAttachments) AddFile(objAttachment.FileName); }
/// <summary> /// Carga los parámetros /// </summary> public void LoadParameters(AttachmentsCollection objColAttachments) { // Inicializa el control InitControl(); // Carga los parámetros foreach (Attachment objAttachment in objColAttachments) { AddFile(objAttachment.FileName); } }
/// <summary> /// Obtiene los archivos de la lista /// </summary> public AttachmentsCollection GetParameters() { AttachmentsCollection objColFiles = new AttachmentsCollection(); // Obtiene los parámetros foreach (ListViewItem lsiItem in lswParameters.Items) objColFiles.Add(lsiItem.Text); // Devuelve la colección de archivos return objColFiles; }
public RequestMessage(MethodType intMethod, string strURL) { // Asigna las propiedades Method = intMethod; URL = strURL; // Asigna los valores básicos ContentType = "text/xml"; // Define los objetos UrlParameters = new ParameterDataCollection(); QueryParameters = new ParameterDataCollection(); Attachments = new AttachmentsCollection(); }
/// <summary> /// Obtiene los archivos de la lista /// </summary> public AttachmentsCollection GetParameters() { AttachmentsCollection objColFiles = new AttachmentsCollection(); // Obtiene los parámetros foreach (ListViewItem lsiItem in lswParameters.Items) { objColFiles.Add(lsiItem.Text); } // Devuelve la colección de archivos return(objColFiles); }
public static AttachmentsCollection GetbyUser(string CreatedUser, int CompanyID) { AttachmentsCollection collection = new AttachmentsCollection(); Attachments obj; var sqlParams = new SqlParameter[] { new SqlParameter("@CreatedUser", CreatedUser), new SqlParameter("@CompanyID", CompanyID), }; using (var reader = SqlHelper.ExecuteReader("tbAttachment_GetAll_byUser", sqlParams)) { while (reader.Read()) { obj = GetItemFromReader(reader); collection.Add(obj); } } return(collection); }
public static AttachmentsCollection GetAllItem(int CompanyID) { AttachmentsCollection collection = new AttachmentsCollection(); var sqlParams = new SqlParameter[] { new SqlParameter("@CompanyID", CompanyID), }; using (var reader = SqlHelper.ExecuteReader("tbAttachment_GetAll", sqlParams)) { while (reader.Read()) { Attachments obj = new Attachments(); obj = GetItemFromReader(reader); collection.Add(obj); } } return(collection); }
public RedmineServiceContext(Uri serviceUri, string apiKey) { _serviceUri = serviceUri; _apiKey = apiKey; _news = new NewsCollection(this); _projects = new ProjectsCollection(this); _issues = new IssuesCollection(this); _users = new UsersCollection(this); _userRoles = new UserRolesCollection(this); _relations = new IssueRelationsCollection(this); _trackers = new IssueTrackersCollection(this); _statuses = new IssueStatusesCollection(this); _priorities = new IssuePrioritiesCollection(this); _categories = new IssueCategoriesCollection(this); _versions = new ProjectVersionsCollection(this); _attachments = new AttachmentsCollection(this); _customFields = new CustomFieldsCollection(this); _queries = new QueriesCollection(this); _syncRoot = new object(); }
public Task SendMailTask(AsyncCodeActivityContext context, Receiver reciever, MailMessage mailMessage, CancellationToken cancellationToken, bool isNewMessage, string body) { List <string> attachments = Attachments ?? new List <string>(); foreach (InArgument <string> file in Files) { AddAttachments(attachments, file.Get(context)); } foreach (string item in AttachmentsCollection.Get(context).EmptyIfNull()) { AddAttachments(attachments, item); } string to = To.Get(context); string cc = Cc.Get(context); string bcc = Bcc.Get(context); string sentOnBehalfOfName = SentOnBehalfOfName.Get(context); string account = Account.Get(context); return(Task.Factory.StartNew(delegate { OutlookAPI.SendMail(mailMessage, account, sentOnBehalfOfName, to, cc, bcc, attachments, IsDraft, IsBodyHtml); })); }
/// <summary> /// Obtiene los datos a enviar cuando hay nombres de archivos /// </summary> private byte[] GetMultipartFormData(string strBoundary, ParameterDataCollection objColQueryString, AttachmentsCollection objColAttachments) { byte [] arrBytFormData; // Escribe los datos en un stream en memoria using (MemoryStream stmData = new MemoryStream()) { System.Text.UTF8Encoding objEncoding = new System.Text.UTF8Encoding(); string strFooter = "\r\n--" + strBoundary + "--\r\n"; // Asigna los archivos foreach (Attachment objAttachment in objColAttachments) { byte [] arrBytHeader = objEncoding.GetBytes(string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\";\r\nContent-Type: {3}\r\n\r\n", strBoundary, Path.GetFileName(objAttachment.FileName), Path.GetFileName(objAttachment.FileName), objAttachment.ContentType)); byte [] arrBytFile = ReadFile(objAttachment.FileName); // Escribe la cabecera stmData.Write(arrBytHeader, 0, arrBytHeader.Length); // Escribe los datos del archivo stmData.Write(arrBytFile, 0, arrBytFile.Length); // Añade un salto de línea para permitir que se envíen varios archivos stmData.Write(objEncoding.GetBytes("\r\n"), 0, 2); } // Asigna los parámetros foreach (ParameterData objQueryString in objColQueryString) { byte [] arrBytPostData = objEncoding.GetBytes(string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"\r\n\r\n{2}\r\n", strBoundary, objQueryString.Key, objQueryString.ValueEncoded)); // Escribe los datos stmData.Write(arrBytPostData, 0, arrBytPostData.Length); } // Añade el final de la solicitud stmData.Write(objEncoding.GetBytes(strFooter), 0, strFooter.Length); // Pasa los datos del stream de memoria al buffer stmData.Position = 0; arrBytFormData = new byte[stmData.Length]; stmData.Read(arrBytFormData, 0, arrBytFormData.Length); // Cierra el stream de memoria stmData.Close(); } // Devuelve el array de bytes de datos return(arrBytFormData); }
protected override void Execute(CodeActivityContext context) { string username = Email.Get(context); //发送端账号 string password = Password.Get(context); //发送端密码(这个客户端重置后的密码) string server = Server.Get(context); //邮件服务器 Int32 port = Port.Get(context); //端口号 string from = From.Get(context); //发送者地址(一般与发送账号相同) string name = Name.Get(context); //发送者名称 string[] receivers_To = Receivers_To.Get(context); //收件人 string[] receivers_Cc = Receivers_Cc.Get(context); //抄送 string[] recervers_Bcc = Receivers_Bcc.Get(context); //密送 string mailTopic = MailTopic.Get(context); //邮件的主题 string mailBody = MailBody.Get(context); //发送的邮件正文 //string[] attachFiles = AttachFiles.Get(context); //附件列表 MimeMessage transMsg = TransMailMessage.Get(context); try { List <string> attachments = Attachments ?? new List <string>(); foreach (InArgument <string> file in Files) { AddAttachments(attachments, file.Get(context)); } foreach (string item in AttachmentsCollection.Get(context).EmptyIfNull()) { AddAttachments(attachments, item); } MailKit.Net.Smtp.SmtpClient client = new MailKit.Net.Smtp.SmtpClient(); client.Connect(server, port, SecureConnection); client.Authenticate(username, password); var multipart = new Multipart("mixed"); MimeMessage msg = new MimeMessage(); if (name == null && from == null) { msg.From.Add((new MailboxAddress(username))); } else if (name == null && from != null) { msg.From.Add((new MailboxAddress(from))); } else if (name != null && from == null) { msg.From.Add((new MailboxAddress(name, username))); } else { msg.From.Add((new MailboxAddress(name, from))); } if (receivers_To != null) { foreach (string receiver in receivers_To) { msg.To.Add((new MailboxAddress(receiver))); } } if (receivers_Cc != null) { foreach (string receiver in receivers_Cc) { msg.Cc.Add((new MailboxAddress(receiver))); } } if (recervers_Bcc != null) { foreach (string receiver in recervers_Bcc) { msg.Bcc.Add((new MailboxAddress(receiver))); } } if (mailBody != null) { if (!IsBodyHtml) { var plain = new TextPart(TextFormat.Plain) { Text = mailBody }; multipart.Add(plain); } else { var Html = new TextPart(TextFormat.Html) { Text = mailBody }; multipart.Add(Html); } } else if (transMsg != null) { if (!IsBodyHtml) { var plain = new TextPart(TextFormat.Plain) { Text = transMsg.TextBody }; multipart.Add(plain); } else { var Html = new TextPart(TextFormat.Html) { Text = transMsg.HtmlBody }; multipart.Add(Html); } } else { var plain = new TextPart(TextFormat.Plain) { Text = "" }; multipart.Add(plain); } if (mailTopic != null) { msg.Subject = mailTopic; } else if (transMsg != null) { msg.Subject = transMsg.Subject; } msg.Priority = msgProperty; if (Files != null) { foreach (var p in Files) { try { if (!string.IsNullOrEmpty(p.ToString())) { var attimg = new MimePart() { Content = new MimeContent(File.OpenRead(p.ToString()), ContentEncoding.Default), ContentDisposition = new ContentDisposition(ContentDisposition.Attachment), ContentTransferEncoding = ContentEncoding.Base64, FileName = Path.GetFileName(p.ToString()) }; multipart.Add(attimg); } } catch (FileNotFoundException ex) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "文件未找到,请检查有效路径", ex.Message); } } } if (transMsg != null) { foreach (MimeEntity part in transMsg.Attachments) { multipart.Add(part); } } msg.Body = multipart; try { client.Send(msg); Debug.WriteLine("发送成功"); } catch (System.Net.Mail.SmtpException ex) { Debug.WriteLine(ex.Message, "发送邮件出错"); } } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "发送邮件失败", e.Message); } }
/// <summary> /// Obtiene los datos a enviar cuando hay nombres de archivos /// </summary> private byte[] GetMultipartFormData(string strBoundary, ParameterDataCollection objColQueryString, AttachmentsCollection objColAttachments) { byte [] arrBytFormData; // Escribe los datos en un stream en memoria using (MemoryStream stmData = new MemoryStream()) { System.Text.UTF8Encoding objEncoding = new System.Text.UTF8Encoding(); string strFooter = "\r\n--" + strBoundary + "--\r\n"; // Asigna los archivos foreach (Attachment objAttachment in objColAttachments) { byte [] arrBytHeader = objEncoding.GetBytes(string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\";\r\nContent-Type: {3}\r\n\r\n", strBoundary, Path.GetFileName(objAttachment.FileName), Path.GetFileName(objAttachment.FileName), objAttachment.ContentType)); byte [] arrBytFile = ReadFile(objAttachment.FileName); // Escribe la cabecera stmData.Write(arrBytHeader, 0, arrBytHeader.Length); // Escribe los datos del archivo stmData.Write(arrBytFile, 0, arrBytFile.Length); // Añade un salto de línea para permitir que se envíen varios archivos stmData.Write(objEncoding.GetBytes("\r\n"), 0, 2); } // Asigna los parámetros foreach (ParameterData objQueryString in objColQueryString) { byte [] arrBytPostData = objEncoding.GetBytes(string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"\r\n\r\n{2}\r\n", strBoundary, objQueryString.Key, objQueryString.ValueEncoded)); // Escribe los datos stmData.Write(arrBytPostData, 0, arrBytPostData.Length); } // Añade el final de la solicitud stmData.Write(objEncoding.GetBytes(strFooter), 0, strFooter.Length); // Pasa los datos del stream de memoria al buffer stmData.Position = 0; arrBytFormData = new byte[stmData.Length]; stmData.Read(arrBytFormData, 0, arrBytFormData.Length); // Cierra el stream de memoria stmData.Close(); } // Devuelve el array de bytes de datos return arrBytFormData; }