Rfc 2822 3.4 address-list. Rfc defines two types of addresses mailbox and group.

address-list syntax: address *("," address).

address syntax: mailbox / group.

mailbox syntax: ['"'dispaly-name'"' ]<localpart@domain>.

group syntax: '"'dispaly-name'":' [mailbox *(',' mailbox)]';'.

Inheritance: IEnumerable
 public static bool SendSmartHost(string codeOpenForm, string Title, string DisplayFrom, AddressList To,
     AddressList CC, AddressList Bcc, string Subject, string File)
 {
     if (codeOpenForm != null && codeOpenForm != "")
     {
         Subject += "<br>__________________________________________</br>";
         Subject += "<br><i>" + codeOpenForm + "<i></br>";
     }
     return HelpEmail.SendSmartHost(Title, DisplayFrom, To, CC, Bcc, Subject, File);
 }
        public static AddressList GetAddressList(long[] Keys)
        {
            QueryBuilder query = new QueryBuilder(@"SELECT e.ID, e.NAME, cat.USERID as ID, cat.USERNAME, e.EMAIL FROM USER_CAT cat left join DM_NHAN_VIEN e on e.ID=cat.EMPLOYEE_ID WHERE 1=1");
            query.addBoolean("e.VISIBLE_BIT", true);
            query.addCondition("(EMAIL<>'')");
            if (Keys.Length > 0)
                query.addID("e.ID", Keys);
            DataSet dsTo = HelpDB.getDatabase().LoadDataSet(query, "CAT");

            AddressList to = new AddressList();
            foreach (DataRow row in dsTo.Tables[0].Rows)
            {
                if (!to.ToAddressListString().Contains(row["EMAIL"].ToString()))
                    to.Add(new MailboxAddress(row["NAME"].ToString(), row["EMAIL"].ToString()));
            }

            return to;
        }
Example #3
0
		/// <summary>
		/// Creates simple mime message.
		/// </summary>
		/// <param name="from">Header field From: value.</param>
		/// <param name="to">Header field To: value.</param>
		/// <param name="subject">Header field Subject: value.</param>
		/// <param name="bodyText">Body text of message. NOTE: Pass null is body text isn't wanted.</param>
		/// <param name="bodyHtml">Body HTML text of message. NOTE: Pass null is body HTML text isn't wanted.</param>
		/// <returns></returns>
		public static Mime CreateSimple(AddressList from,AddressList to,string subject,string bodyText,string bodyHtml)
		{
			return CreateSimple(from,to,subject,bodyText,bodyHtml,null);
		}
Example #4
0
        /// <summary>
        /// Creates simple mime message with attachments.
        /// </summary>
        /// <param name="from">Header field From: value.</param>
        /// <param name="to">Header field To: value.</param>
        /// <param name="subject">Header field Subject: value.</param>
        /// <param name="bodyText">Body text of message. NOTE: Pass null is body text isn't wanted.</param>
        /// <param name="bodyHtml">Body HTML text of message. NOTE: Pass null is body HTML text isn't wanted.</param>
        /// <param name="attachmentFileNames">Attachment file names. Pass null if no attachments. NOTE: File name must contain full path to file, for example: c:\test.pdf.</param>
        /// <returns></returns>
        public static Mime CreateSimple(AddressList from, AddressList to, string subject, string bodyText, string bodyHtml, string[] attachmentFileNames)
        {
            Mime m = new Mime();

            MimeEntity mainEntity = m.MainEntity;

            mainEntity.From    = from;
            mainEntity.To      = to;
            mainEntity.Subject = subject;

            // There are no atachments
            if (attachmentFileNames == null || attachmentFileNames.Length == 0)
            {
                // If bodyText and bodyHtml both specified
                if (bodyText != null && bodyHtml != null)
                {
                    mainEntity.ContentType = MediaType_enum.Multipart_alternative;

                    MimeEntity textEntity = mainEntity.ChildEntities.Add();
                    textEntity.ContentType             = MediaType_enum.Text_plain;
                    textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
                    textEntity.DataText = bodyText;

                    MimeEntity textHtmlEntity = mainEntity.ChildEntities.Add();
                    textHtmlEntity.ContentType             = MediaType_enum.Text_html;
                    textHtmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
                    textHtmlEntity.DataText = bodyHtml;
                }
                // There is only body text
                else if (bodyText != null)
                {
                    MimeEntity textEntity = mainEntity;
                    textEntity.ContentType             = MediaType_enum.Text_plain;
                    textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
                    textEntity.DataText = bodyText;
                }
                // There is only body html text
                else if (bodyHtml != null)
                {
                    MimeEntity textHtmlEntity = mainEntity;
                    textHtmlEntity.ContentType             = MediaType_enum.Text_html;
                    textHtmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
                    textHtmlEntity.DataText = bodyHtml;
                }
            }
            // There are attachments
            else
            {
                mainEntity.ContentType = MediaType_enum.Multipart_mixed;

                // If bodyText and bodyHtml both specified
                if (bodyText != null && bodyHtml != null)
                {
                    MimeEntity multiPartAlternativeEntity = mainEntity.ChildEntities.Add();
                    multiPartAlternativeEntity.ContentType = MediaType_enum.Multipart_alternative;

                    MimeEntity textEntity = multiPartAlternativeEntity.ChildEntities.Add();
                    textEntity.ContentType             = MediaType_enum.Text_plain;
                    textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
                    textEntity.DataText = bodyText;

                    MimeEntity textHtmlEntity = multiPartAlternativeEntity.ChildEntities.Add();
                    textHtmlEntity.ContentType             = MediaType_enum.Text_html;
                    textHtmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
                    textHtmlEntity.DataText = bodyHtml;
                }
                // There is only body text
                else if (bodyText != null)
                {
                    MimeEntity textEntity = mainEntity.ChildEntities.Add();
                    textEntity.ContentType             = MediaType_enum.Text_plain;
                    textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
                    textEntity.DataText = bodyText;
                }
                // There is only body html text
                else if (bodyHtml != null)
                {
                    MimeEntity textHtmlEntity = mainEntity.ChildEntities.Add();
                    textHtmlEntity.ContentType             = MediaType_enum.Text_html;
                    textHtmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
                    textHtmlEntity.DataText = bodyHtml;
                }

                foreach (string fileName in attachmentFileNames)
                {
                    MimeEntity attachmentEntity = mainEntity.ChildEntities.Add();
                    attachmentEntity.ContentType                 = MediaType_enum.Application_octet_stream;
                    attachmentEntity.ContentDisposition          = ContentDisposition_enum.Attachment;
                    attachmentEntity.ContentTransferEncoding     = ContentTransferEncoding_enum.Base64;
                    attachmentEntity.ContentDisposition_FileName = Core.GetFileNameFromPath(fileName);
                    attachmentEntity.DataFromFile(fileName);
                }
            }

            return(m);
        }
Example #5
0
 /// <summary>
 /// Creates simple mime message.
 /// </summary>
 /// <param name="from">Header field From: value.</param>
 /// <param name="to">Header field To: value.</param>
 /// <param name="subject">Header field Subject: value.</param>
 /// <param name="bodyText">Body text of message. NOTE: Pass null is body text isn't wanted.</param>
 /// <param name="bodyHtml">Body HTML text of message. NOTE: Pass null is body HTML text isn't wanted.</param>
 /// <returns></returns>
 public static Mime CreateSimple(AddressList from, AddressList to, string subject, string bodyText, string bodyHtml)
 {
     return(CreateSimple(from, to, subject, bodyText, bodyHtml, null));
 }
        /// <summary>
        /// Executes specified actions.
        /// </summary>
        /// <param name="dvActions">Dataview what contains actions to be executed.</param>
        /// <param name="server">Reference to owner virtual server.</param>
        /// <param name="message">Recieved message.</param>
        /// <param name="sender">MAIL FROM: command value.</param>
        /// <param name="to">RCPT TO: commands values.</param>
        public GlobalMessageRuleActionResult DoActions(DataView dvActions,VirtualServer server,Stream message,string sender,string[] to)
        {
            // TODO: get rid of MemoryStream, move to Stream

              //    bool   messageChanged = false;
            bool   deleteMessage  = false;
            string storeFolder    = null;
            string errorText      = null;

            // Loop actions
            foreach(DataRowView drV in dvActions){
                GlobalMessageRuleAction_enum action     = (GlobalMessageRuleAction_enum)drV["ActionType"];
                byte[]                       actionData = (byte[])drV["ActionData"];

                // Reset stream position
                message.Position = 0;

                #region AutoResponse

                /* Description: Sends specified autoresponse message to sender.
                    Action data structure:
                        <ActionData>
                            <From></From>
                            <Message></Message>
                        </ActionData>
                */

                if(action == GlobalMessageRuleAction_enum.AutoResponse){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    string smtp_from   = table.GetValue("From");
                    string responseMsg = table.GetValue("Message");

                    // See if we have header field X-LS-MailServer-AutoResponse, never answer to auto response.
                    HeaderFieldCollection header = new HeaderFieldCollection();
                    header.Parse(message);
                    if(header.Contains("X-LS-MailServer-AutoResponse:")){
                        // Just skip
                    }
                    else{
                        Mime autoresponseMessage = Mime.Parse(System.Text.Encoding.Default.GetBytes(responseMsg));

                        // Add header field 'X-LS-MailServer-AutoResponse:'
                        autoresponseMessage.MainEntity.Header.Add("X-LS-MailServer-AutoResponse:","");
                        // Update message date
                        autoresponseMessage.MainEntity.Date = DateTime.Now;

                        // Set To: if not explicity set
                        if(autoresponseMessage.MainEntity.To == null || autoresponseMessage.MainEntity.To.Count == 0){
                            if(autoresponseMessage.MainEntity.To == null){
                                AddressList t = new AddressList();
                                t.Add(new MailboxAddress(sender));
                                autoresponseMessage.MainEntity.To = t;
                            }
                            else{
                                autoresponseMessage.MainEntity.To.Add(new MailboxAddress(sender));
                            }
                        }
                        // Update Subject: variables, if any
                        if(autoresponseMessage.MainEntity.Subject != null){
                            if(header.Contains("Subject:")){
                                autoresponseMessage.MainEntity.Subject = autoresponseMessage.MainEntity.Subject.Replace("#SUBJECT",header.GetFirst("Subject:").Value);
                            }
                        }

                        server.ProcessAndStoreMessage(smtp_from,new string[]{sender},new MemoryStream(autoresponseMessage.ToByteData()),null);
                    }
                }

                #endregion

                #region Delete Message

                /* Description: Deletes message.
                    Action data structure:
                        <ActionData>
                        </ActionData>
                */

                else if(action == GlobalMessageRuleAction_enum.DeleteMessage){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    deleteMessage = true;
                }

                #endregion

                #region ExecuteProgram

                /* Description: Executes specified program.
                    Action data structure:
                        <ActionData>
                            <Program></Program>
                            <Arguments></Arguments>
                        </ActionData>
                */

                else if(action == GlobalMessageRuleAction_enum.ExecuteProgram){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo();
                    pInfo.FileName = table.GetValue("Program");
                    pInfo.Arguments = table.GetValue("Arguments");
                    pInfo.CreateNoWindow = true;
                    System.Diagnostics.Process.Start(pInfo);
                }

                #endregion

                #region ForwardToEmail

                /* Description: Forwards email to specified email.
                    Action data structure:
                        <ActionData>
                            <Email></Email>
                        </ActionData>
                */

                else if(action == GlobalMessageRuleAction_enum.ForwardToEmail){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    // See If message has X-LS-MailServer-ForwardedTo: and equals to "Email".
                    // If so, then we have cross reference forward, don't forward that message
                    LumiSoft.Net.Mime.HeaderFieldCollection header = new HeaderFieldCollection();
                    header.Parse(message);
                    bool forwardedAlready = false;
                    if(header.Contains("X-LS-MailServer-ForwardedTo:")){
                        foreach(HeaderField headerField in header.Get("X-LS-MailServer-ForwardedTo:")){
                            if(headerField.Value == table.GetValue("Email")){
                                forwardedAlready = true;
                                break;
                            }
                        }
                    }

                    // Reset stream position
                    message.Position = 0;

                    if(forwardedAlready){
                        // Just skip
                    }
                    else{
                        // Add header field 'X-LS-MailServer-ForwardedTo:'
                        MemoryStream msFwMessage = new MemoryStream();
                        byte[] fwField = System.Text.Encoding.Default.GetBytes("X-LS-MailServer-ForwardedTo: " + table.GetValue("Email") + "\r\n");
                        msFwMessage.Write(fwField,0,fwField.Length);
                        SCore.StreamCopy(message,msFwMessage);

                        server.ProcessAndStoreMessage(sender,new string[]{table.GetValue("Email")},msFwMessage,null);
                    }
                }

                #endregion

                #region ForwardToHost

                /* Description: Forwards email to specified host.
                                All RCPT TO: recipients are preserved.
                    Action data structure:
                        <ActionData>
                            <Host></Host>
                            <Port></Port>
                        </ActionData>
                */

                else if(action == GlobalMessageRuleAction_enum.ForwardToHost){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    foreach(string t in to){
                        message.Position = 0;
                        server.RelayServer.StoreRelayMessage(message,table.GetValue("Host") + ":" + table.GetValue("Port"),sender,t);
                    }
                    message.Position = 0; // TODO: does it later that needed there, must do in called place instead ?
                }

                #endregion

                #region StoreToDiskFolder

                /* Description: Stores message to specified disk folder.
                    Action data structure:
                        <ActionData>
                            <Folder></Folder>
                        </ActionData>
                */

                else if(action == GlobalMessageRuleAction_enum.StoreToDiskFolder){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    string folder = table.GetValue("Folder");
                    if(!folder.EndsWith("\\")){
                        folder += "\\";
                    }

                    if(Directory.Exists(folder)){
                        using(FileStream fs = File.Create(folder + DateTime.Now.ToString("ddMMyyyyHHmmss") + "_" + Guid.NewGuid().ToString().Replace('-','_').Substring(0,8) + ".eml")){
                            SCore.StreamCopy(message,fs);
                        }
                    }
                    else{
                        // TODO: log error somewhere
                    }
                }

                #endregion

                #region StoreToIMAPFolder

                /* Description: Stores message to specified IMAP folder.
                    Action data structure:
                        <ActionData>
                            <Folder></Folder>
                        </ActionData>
                */

                else if(action == GlobalMessageRuleAction_enum.StoreToIMAPFolder){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);
                    storeFolder = table.GetValue("Folder");
                }

                #endregion

                #region AddHeaderField

                /* Description: Add specified header field to message main header.
                    Action data structure:
                        <ActionData>
                            <HeaderFieldName></HeaderFieldName>
                            <HeaderFieldValue></HeaderFieldValue>
                        </ActionData>
                */

                else if(action == GlobalMessageRuleAction_enum.AddHeaderField){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    Mime mime = Mime.Parse(message);
                    mime.MainEntity.Header.Add(table.GetValue("HeaderFieldName"),table.GetValue("HeaderFieldValue"));
                    message.SetLength(0);
                    mime.ToStream(message);

                //  messageChanged = true;
                }

                #endregion

                #region RemoveHeaderField

                /* Description: Removes specified header field from message mian header.
                    Action data structure:
                        <ActionData>
                            <HeaderFieldName></HeaderFieldName>
                        </ActionData>
                */

                else if(action == GlobalMessageRuleAction_enum.RemoveHeaderField){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    Mime mime = Mime.Parse(message);
                    mime.MainEntity.Header.RemoveAll(table.GetValue("HeaderFieldName"));
                    message.SetLength(0);
                    mime.ToStream(message);

                //    messageChanged = true;
                }

                #endregion

                #region SendErrorToClient

                /* Description: Sends error to currently connected client. NOTE: Error text may contain ASCII printable chars only and maximum length is 500.
                    Action data structure:
                        <ActionData>
                            <ErrorText></ErrorText>
                        </ActionData>
                */

                else if(action == GlobalMessageRuleAction_enum.SendErrorToClient){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    errorText = table.GetValue("ErrorText");
                }

                #endregion

                #region StoreToFTPFolder

                /* Description: Stores message to specified FTP server folder.
                    Action data structure:
                        <ActionData>
                            <Server></Server>
                            <Port></Server>
                            <User></User>
                            <Password></Password>
                            <Folder></Folder>
                        </ActionData>
                */

                else if(action == GlobalMessageRuleAction_enum.StoreToFTPFolder){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    _MessageRuleAction_FTP_AsyncSend ftpSend = new _MessageRuleAction_FTP_AsyncSend(
                        table.GetValue("Server"),
                        Convert.ToInt32(table.GetValue("Port")),
                        table.GetValue("User"),
                        table.GetValue("Password"),
                        table.GetValue("Folder"),
                        message,
                        DateTime.Now.ToString("ddMMyyyyHHmmss") + "_" + Guid.NewGuid().ToString().Replace('-','_').Substring(0,8) + ".eml"
                    );
                }

                #endregion

                #region PostToNNTPNewsGroup

                /* Description: Posts message to specified NNTP newsgroup.
                    Action data structure:
                        <ActionData>
                            <Server></Server>
                            <Port></Server>
                            <User></User>
                            <Password></Password>
                            <Newsgroup></Newsgroup>
                        </ActionData>
                */

                else if(action == GlobalMessageRuleAction_enum.PostToNNTPNewsGroup){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    // Add header field "Newsgroups: newsgroup", NNTP server demands it.
                    Mime mime = Mime.Parse(message);
                    if(!mime.MainEntity.Header.Contains("Newsgroups:")){
                        mime.MainEntity.Header.Add("Newsgroups:",table.GetValue("Newsgroup"));
                    }

                    _MessageRuleAction_NNTP_Async nntp = new _MessageRuleAction_NNTP_Async(
                        table.GetValue("Server"),
                        Convert.ToInt32(table.GetValue("Port")),
                        table.GetValue("Newsgroup"),
                        new MemoryStream(mime.ToByteData())
                     );

                }

                #endregion

                #region PostToHTTP

                /* Description: Posts message to specified page via HTTP.
                    Action data structure:
                        <ActionData>
                            <URL></URL>
                            <FileName></FileName>
                        </ActionData>
                */

                else if(action == GlobalMessageRuleAction_enum.PostToHTTP){
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    _MessageRuleAction_HTTP_Async http = new _MessageRuleAction_HTTP_Async(
                        table.GetValue("URL"),
                        message
                    );
                }

                #endregion

            }

            return new GlobalMessageRuleActionResult(deleteMessage,storeFolder,errorText);
        }
        /// <summary>
        /// Constructs ENVELOPE addresses structure.
        /// </summary>
        /// <param name="addressList">Address list.</param>
        /// <returns></returns>
        private static string ConstructAddresses(AddressList addressList)
        {
            StringBuilder retVal = new StringBuilder();
            retVal.Append("(");

            foreach(MailboxAddress address in addressList.Mailboxes){
                retVal.Append(ConstructAddress(address));
            }

            retVal.Append(")");

            return retVal.ToString();
        }
        /// <summary>
        /// Creates Mime message based on UI data.
        /// </summary>
        private Mime CreateMessage()
        {
            Mime m = new Mime();

            MimeEntity texts_enity        = null;
            MimeEntity attachments_entity = null;
            if(m_pAttachments.Items.Count > 0){
                m.MainEntity.ContentType = MediaType_enum.Multipart_mixed;
                texts_enity = m.MainEntity.ChildEntities.Add();
                texts_enity.ContentType = MediaType_enum.Multipart_alternative;

                attachments_entity = m.MainEntity;
            }
            else{
                m.MainEntity.ContentType = MediaType_enum.Multipart_alternative;
                texts_enity = m.MainEntity;
            }

            // Main entity settings
            AddressList from = new AddressList();
            from.Parse(m_pFrom.Text);
            m.MainEntity.From = from;
            AddressList to = new AddressList();
            to.Parse("\"" + m_pFolder.User.FullName + "\" <" + m_pFolder.User.FullName + "@localhost>");
            m.MainEntity.To = to;
            m.MainEntity.Subject = m_pSubject.Text;

            // Create text/plain entity
            MimeEntity text_entity = texts_enity.ChildEntities.Add();
            text_entity.ContentType = MediaType_enum.Text_plain;
            text_entity.ContentType_CharSet = "utf-8";
            text_entity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
            text_entity.DataText = m_pText.Text;

            // Create text/rtf entity
            MimeEntity rtfText_entity = texts_enity.ChildEntities.Add();
            rtfText_entity.ContentType = MediaType_enum.Text_html;
            rtfText_entity.ContentType_CharSet = "utf-8";
            rtfText_entity.ContentTransferEncoding = ContentTransferEncoding_enum.Base64;
            rtfText_entity.DataText = RtfToHtml();

            // Create attachment etities
            if(attachments_entity != null){
                foreach(ListViewItem item in m_pAttachments.Items){
                    MimeEntity attachment_entity = attachments_entity.ChildEntities.Add();
                    attachment_entity.ContentType = MediaType_enum.Application_octet_stream;
                    attachment_entity.ContentTransferEncoding = ContentTransferEncoding_enum.Base64;
                    attachment_entity.ContentDisposition = ContentDisposition_enum.Attachment;
                    attachment_entity.ContentDisposition_FileName = Path.GetFileName(item.Tag.ToString());
                    attachment_entity.Data = File.ReadAllBytes(item.Tag.ToString());
                }
            }

            return m;
        }
        /// <summary>
        /// phieuGui: Phiếu sẽ gửi mail
        /// </summary>
        /// <param name="phieu"></param>
        /// <param name="tinhTrang"></param>
        /// <param name="dt"></param>
        /// <param name="phieuGui"></param>
        /// <returns></returns>
        public static bool _SendThongBao(long[] NguoiNhanMail, DOTimeInOut phieu, string tinhTrang, params object[] phieuGui)
        {
            AddressList To = new AddressList();
            string title = string.Empty;
            StringBuilder subject;
            //Thứ
            string date;
            string classform = "";
            switch (phieu.NGAY_LAM_VIEC.DayOfWeek)
            {
                case DayOfWeek.Monday:
                    date = "Thứ hai, ";
                    break;
                case DayOfWeek.Tuesday:
                    date = "Thứ ba, ";
                    break;
                case DayOfWeek.Wednesday:
                    date = "Thứ tư, ";
                    break;
                case DayOfWeek.Thursday:
                    date = "Thứ năm, ";
                    break;
                case DayOfWeek.Friday:
                    date = "Thứ sáu, ";
                    break;
                case DayOfWeek.Saturday:
                    date = "Thứ bảy, ";
                    break;
                default:
                    date = "Chủ nhật, ";
                    break;
            };

            //
            if (string.Compare(phieuGui[0].ToString(), LoaiPhieu.PhieuXinNghiPhep.ToString()) == 0)
            {
                ///1.Nội dung

                classform = typeof(frmNghiPhep).FullName;
                StringBuilder thoiGianNghi = new StringBuilder();
                if (phieu.NGHI_BUOI_SANG == "Y" && phieu.NGHI_BUOI_CHIEU == "Y") thoiGianNghi.Append("Nghỉ cả ngày");
                else
                {
                    if (phieu.NGHI_BUOI_SANG == "Y") thoiGianNghi.Append("Nghỉ buổi sáng");
                    if (phieu.NGHI_BUOI_CHIEU == "Y") thoiGianNghi.Append("Nghỉ buổi chiều");
                }

                subject = new StringBuilder(string.Format(PLConst.DES_MAIL_XNP, DMNhanVienX.I.GetEmployeeFullName(phieu.NV_ID),
                        thoiGianNghi.ToString(), date + phieu.NGAY_LAM_VIEC.ToShortDateString(), phieu.NGHI_PHEP_NAM == "Y" ? "Nghỉ phép năm" : "Nghỉ không lương",
                        phieu.LY_DO));
                if (tinhTrang == PLConst.CHO_DUYET)
                {
                    List<long> lstUser = new List<long>(NguoiNhanMail);
                    if (!lstUser.Contains(phieu.NV_ID)) lstUser.Add(phieu.NV_ID);
                    title = "Có phiếu xin nghỉ phép đang chờ duyệt";
                    To = HelpZPLOEmail.GetAddressList((lstUser.ToArray()));
                }
                else if (tinhTrang == PLConst.DUYET)
                {
                    title = "Có phiếu xin nghỉ phép được duyệt";
                    To = HelpZPLOEmail.GetAddressList(new long[] { phieu.NV_ID });
                }
                else if (tinhTrang == PLConst.KHONG_DUYET)
                {
                    title = "Có phiếu xin nghỉ phép không được duyệt.";
                    To = HelpZPLOEmail.GetAddressList(new long[] { phieu.NV_ID });
                }
                else
                {
                    title = "Có phiếu xin nghỉ phép đã xóa";
                    To = HelpZPLOEmail.GetAddressList(new long[] { phieu.NV_ID });
                }
            }
            else if (string.Compare(phieuGui[0].ToString(), LoaiPhieu.PhieuXacNhanLamViec.ToString()) == 0)
            {
                classform = typeof(frmPhieuXNLamViec).FullName;
                subject = new StringBuilder(string.Format(PLConst.DES_MAIL_XNLV, DMNhanVienX.I.GetEmployeeFullName(phieu.NV_ID),
                        date + phieu.NGAY_LAM_VIEC.ToShortDateString(), Convert.ToDateTime(phieu.GIO_BAT_DAU.ToString()).ToString("HH:mm"),
                        Convert.ToDateTime(phieu.GIO_KET_THUC.ToString()).ToString("HH:mm"), phieu.NOI_DUNG));
                if (tinhTrang == PLConst.CHO_DUYET)
                {
                    List<long> lstUser = new List<long>(NguoiNhanMail);

                    if (!lstUser.Contains(phieu.NV_ID)) lstUser.Add(phieu.NV_ID);
                    title = "Có phiếu xác nhận làm việc đang chờ duyệt";
                    To = HelpZPLOEmail.GetAddressList((lstUser.ToArray()));
                }
                else if (tinhTrang == PLConst.DUYET)
                {
                    title = "Có phiếu xác nhận làm việc được duyệt";
                    To = HelpZPLOEmail.GetAddressList(new long[] { phieu.NV_ID });
                }
                else if (tinhTrang == PLConst.KHONG_DUYET)
                {
                    title = "Có phiếu xác nhận làm việc không được duyệt";
                    To = HelpZPLOEmail.GetAddressList(new long[] { phieu.NV_ID });
                }
                else
                {
                    title = "Có phiếu xác nhận làm việc đã xóa";
                    To = HelpZPLOEmail.GetAddressList(new long[] { phieu.NV_ID });
                }
            }
            else
            {
                classform = typeof(frmPhieuRaVaoCty).FullName;

                subject = new StringBuilder(string.Format(PLConst.DES_MAIL_RVCTY, DMNhanVienX.I.GetEmployeeFullName(phieu.NV_ID),
                       date + phieu.NGAY_LAM_VIEC.ToShortDateString(), Convert.ToDateTime(phieu.GIO_BAT_DAU.ToString()).ToString("HH:mm"),
                       Convert.ToDateTime(phieu.GIO_KET_THUC.ToString()).ToString("HH:mm"), phieu.NOI_DUNG));
                if (tinhTrang == PLConst.CHO_DUYET)
                {
                    List<long> lstUser = new List<long>(NguoiNhanMail);
                    if (!lstUser.Contains(phieu.NV_ID)) lstUser.Add(phieu.NV_ID);
                    title = "Có phiếu ra vào công ty đang chờ duyệt";
                    To = HelpZPLOEmail.GetAddressList((lstUser.ToArray()));
                }
                else if (tinhTrang == PLConst.DUYET)
                {
                    title = "Có phiếu ra vào công ty được duyệt";
                    To = HelpZPLOEmail.GetAddressList(new long[] { phieu.NV_ID });
                }
                else if (tinhTrang == PLConst.KHONG_DUYET)
                {
                    title = "Có phiếu ra vào công ty không được duyệt";
                    To = HelpZPLOEmail.GetAddressList(new long[] { phieu.NV_ID });
                }
                else
                {
                    title = "Có phiếu ra vào công ty đã xóa";
                    To = HelpZPLOEmail.GetAddressList(new long[] { phieu.NV_ID });
                }
            }
            title = HelpStringBuilder.GetTitleMailNewPageper(title);
            ///2.Gửi mail
            return HelpZPLOEmail.SendSmartHost(HelpAutoOpenForm.GeneratingCodeFromForm(classform, phieu.ID), title, null, To, null, null, subject.ToString(), "");
        }
 private bool CheckValidation()
 {
     bool bFlag = true;
     this.errorProvider.ClearErrors();
     bFlag = GUIValidation.ShowRequiredError(this.errorProvider, new object[] {
             this.textSubject,"Tiêu đề"
         });
     if (radioGroup1.EditValue.ToString() == "Y")
     {
         EmailNguoiGui = this.GetAddressList(FrameworkParams.currentUser.employee_id);
         if (EmailNguoiGui.Count == 0)
         {
             HelpMsgBox.ShowNotificationMessage("Bạn hiện chưa có địa chỉ email hoặc địa chỉ email không hợp lệ, vui lòng kiểm tra lại!");
             return false;
         }
         EmailNguoiNhan = this.GetAddressList(NguoiNhan);
         if (EmailNguoiNhan.Count == 0)
         {
             HelpMsgBox.ShowNotificationMessage("Người nhận hiện chưa có địa chỉ email hoặc địa chỉ email không hợp lệ, vui lòng kiểm tra lại!");
             return false;
         }
     }
     return bFlag;
 }
        private AddressList GetAddressList(long []Keys )
        {
            QueryBuilder query = new QueryBuilder(@"SELECT e.NAME, cat.USERID as ID, cat.USERNAME FROM USER_CAT cat left join DM_NHAN_VIEN e on e.ID=cat.EMPLOYEE_ID WHERE 1=1");
            query.addBoolean("e.VISIBLE_BIT", true);
            query.addID("cat.USERID", Keys);
            DataSet dsTo = HelpDB.getDatabase().LoadDataSet(query, "CAT");

            AddressList to = new AddressList();
            foreach (DataRow row in dsTo.Tables[0].Rows)
            {
                to.Add(new MailboxAddress(row["NAME"].ToString(), row["USERNAME"].ToString() + "@" + this.textSmartHost.Text));
            }
            return to;
        }
Example #12
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (IsValidate())
            {
                //try...catch dùng trong TH người dùng chọn định dạng giờ của hệ thống trong đó có chứa "t"(AM/PM)
                try
                {
                    System.Convert.ToDateTime(lblThoiGianGui.Text);
                }
                catch {
                    lblThoiGianGui.Text += "M";
                }

                List<long> lstUser = new List<long>(NguoiNhanEmail._SelectedIDs);
                DataTable dt = new DataTable();
                string title = "";
                //Thêm người hỗ trợ vào danh sách gửi mail trong trường hợp ko chọn
                foreach (long id in NguoiHoTro._SelectedIDs)
                    if (!lstUser.Contains(id))
                        lstUser.Add(id);
                //----------------------
                if (IsAdd == true && AfterAddReplySuccesfully == null)
                {
                    try
                    {
                        title = "Có yêu cầu hỗ trợ mới được cập nhật";
                        if (DAYeuCau.Insert(out _YEU_CAU_ID, FrameworkParams.currentUser.employee_id, System.Convert.ToDateTime(lblThoiGianGui.Text), NguoiHoTro._SelectedStrIDs, PLTinhtrang._getSelectedID(), PLLoaiYeuCau._getSelectedID(), PLMucuutien._getSelectedID()
                            , txtChude.Text, NoiDung._getValue(), plMultiChoiceFiles1._DataSource))
                            HelpXtraForm.CloseFormNoConfirm(this);
                    }
                    catch
                    {
                        ErrorMsg.ErrorSave(this);
                    }
                }
                //Save in case ReplySupport.
                else if (IsAdd == true && AfterAddReplySuccesfully != null)
                {
                    DateTime currentDate = HelpDB.getDatabase().GetSystemCurrentDateTime();
                    DOPhanHoi doPhanHoi = new DOPhanHoi(_YEU_CAU_ID, FrameworkParams.currentUser.employee_id,NguoiHoTro._SelectedStrIDs , currentDate, NoiDung._getValue(), FrameworkParams.currentUser.employee_id, currentDate);
                    doPhanHoi.DSTapTinDinhKem = plMultiChoiceFiles1._DataSource;
                    if (DAPhanHoi.Insert(doPhanHoi))
                    {
                        title = "Có phản hồi yêu cầu hỗ trợ mới được cập nhật";
                        HelpXtraForm.CloseFormNoConfirm(this);
                        AfterAddReplySuccesfully(doPhanHoi);
                        //Update status of Support
                        DAYeuCau.UpdateTinhTrangYeuCau(_YEU_CAU_ID, PLTinhtrang._getSelectedID());
                        if (AfterUpdateStatusOfSupport != null) AfterUpdateStatusOfSupport(PLTinhtrang._getSelectedID(), null);
                    }
                    else
                        ErrorMsg.ErrorSave(this);

                }
                else if (IsAdd == false)
                {
                    if (AfterAddReplySuccesfully == null && AfterUpdateReplySuccesfully == null)
                    {
                        title = "Có yêu cầu hỗ trợ mới được cập nhật";
                        DOYeuCau doYeuCau = new DOYeuCau(this._YEU_CAU_ID, FrameworkParams.currentUser.employee_id
                            , NguoiHoTro._SelectedStrIDs, PLLoaiYeuCau._getSelectedID()
                            , HelpNumber.ParseInt32(PLMucuutien._getSelectedID())
                            , txtChude.Text.ToString(), NoiDung._getValue(), System.Convert.ToDateTime(lblThoiGianGui.Text), FrameworkParams.currentUser.employee_id, DateTime.Now, HelpNumber.ParseInt32(PLTinhtrang._getSelectedID()));
                        if (DAYeuCau.Update(this._YEU_CAU_ID, NguoiHoTro._SelectedStrIDs, PLTinhtrang._getSelectedID(), PLLoaiYeuCau._getSelectedID(), PLMucuutien._getSelectedID(), txtChude.Text, NoiDung._getValue(), plMultiChoiceFiles1._DataSource))
                        {
                            if (this.RefreshAfterInsert != null) this.RefreshAfterInsert(doYeuCau);
                            if (AfterUpdateSupportSuccesfully != null) AfterUpdateSupportSuccesfully(doYeuCau);
                            if (AfterUpdateStatusOfSupport != null) AfterUpdateStatusOfSupport(PLTinhtrang._getSelectedID()
                                , new object[]{PLLoaiYeuCau._getSelectedID(),txtChude.Text
                                    ,PLMucuutien._getSelectedID(),NguoiHoTro._SelectedStrIDs,System.Convert.ToDateTime(lblThoiGianGui.Text)});
                            HelpXtraForm.CloseFormNoConfirm(this);
                        }
                        else ErrorMsg.ErrorSave(this);
                    }
                    else
                    {
                        DateTime currentDate = HelpDB.getDatabase().GetSystemCurrentDateTime();
                        DOPhanHoi doPhanHoi = new DOPhanHoi(_YEU_CAU_ID, FrameworkParams.currentUser.employee_id, NguoiHoTro._SelectedStrIDs, currentDate, NoiDung._getValue(), FrameworkParams.currentUser.employee_id, currentDate);
                        doPhanHoi.ID = _YEU_CAU_TL_ID;
                        doPhanHoi.DSTapTinDinhKem = plMultiChoiceFiles1._DataSource;
                        if (DAPhanHoi.Update(doPhanHoi))
                        {
                            title = "Có phản hồi yêu cầu hỗ trợ mới được cập nhật";
                            HelpXtraForm.CloseFormNoConfirm(this);
                            doPhanHoi.DSTapTinDinhKem = plMultiChoiceFiles1._DataSource;
                            if (AfterUpdateReplySuccesfully != null) AfterUpdateReplySuccesfully(doPhanHoi);
                            //Update status of Support
                            DAYeuCau.UpdateTinhTrangYeuCau(_YEU_CAU_ID, PLTinhtrang._getSelectedID());
                            if (AfterUpdateStatusOfSupport != null) AfterUpdateStatusOfSupport(PLTinhtrang._getSelectedID(), null);
                        }
                        else ErrorMsg.ErrorSave(this);
                    }
                }
                //Gửi mail
                if (lstUser.Count > 0 )
                {
                    AddressList To = new AddressList();

                    title = HelpStringBuilder.GetTitleMailNewPageper(title);
                    StringBuilder Subject = new StringBuilder();
                    IDataReader reader = FWDBService.LoadRecord("DM_LOAI_YEU_CAU", "ID", this.PLLoaiYeuCau._getSelectedID());
                    using (reader)
                    {
                        if (reader.Read())
                        {
                            Subject.Append(string.Format(PLConst.DES_MAIL_YCHT, txtChude.Text, reader["NAME"].ToString(), lblNguoiGui.Text, NoiDung.richEditControl.HtmlText));
                        }
                    }
                    if (!lstUser.Contains(FrameworkParams.currentUser.employee_id))
                        lstUser.Add(FrameworkParams.currentUser.employee_id);
                    To = HelpZPLOEmail.GetAddressList(lstUser.ToArray());
                    HelpZPLOEmail.SendSmartHost(
                        HelpAutoOpenForm.GeneratingCodeFromForm(this, _YEU_CAU_ID),
                        title, null, To, null, null, Subject.ToString(), "");
                }
                //-----------------------------------------
            }
        }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            //Thực hiện kiểm tra tính hợp lệ của dữ liệu và lưu
            #region GetData
            doBugProduct.NAME = memoVanDe.Text;
            doBugProduct.LOAI_VAN_DE = loaiVanDe._getSelectedID();
            doBugProduct.TINH_TRANG = Tinh_trang._getSelectedID();
            if (doBugProduct.NGUOI_GUI == 0)//Trường hợp thêm mới
                doBugProduct.NGUOI_GUI = FrameworkParams.currentUser.employee_id;
            try
            {
                doBugProduct.NGAY_GUI = System.Convert.ToDateTime(this.lblThoiGianGui.Text);
            }
            catch
            {
                doBugProduct.NGAY_GUI = System.Convert.ToDateTime(this.lblThoiGianGui.Text + "M");
            }
            doBugProduct.MO_TA_BUG = NoiDung._getValue();
            doBugProduct.NGUOI_NHAN = NguoiNhan._SelectedStrIDs;
            #endregion
            if (IsValidate())
            {
                List<long> lstUser = new List<long>(NguoiNhanEmail._SelectedIDs);
                string title = "";
                //Thêm người hỗ trợ vào danh sách gửi mail trong trường hợp ko chọn
                foreach (long id in NguoiNhan._SelectedIDs)
                    if (!lstUser.Contains(id))
                        lstUser.Add(id);
                if (NoiDung._getValue().Length > 0)
                {
                    if (IsAdd == true && AfterAddReplyIssueSuccessfully == null)
                    {
                        title = "Có vấn đề vừa được cập nhật.";
                        doBugProduct.DSFile = plMultiChoiceFiles1._DataSource;
                        if (!DABugProduct.Instance.Update(doBugProduct))
                            ErrorMsg.ErrorSave(this);
                        else
                        {
                            _ID_Bug = doBugProduct.ID;
                            if (AfterAddIssueSuccessfully != null) AfterAddIssueSuccessfully(doBugProduct);
                            HelpXtraForm.CloseFormNoConfirm(this);
                        }
                    }
                    else if (IsAdd == true && AfterAddReplyIssueSuccessfully != null)
                    {
                        title = "Có phản hồi vấn đề vừa được cập nhật.";

                        doReplyBugProduct = new DOReplyBugProduct(HelpGen.DT(), _ID_Bug
                            , FrameworkParams.currentUser.employee_id,NguoiNhan._SelectedStrIDs, DateTime.Now,
                            NoiDung._getValue());
                        doReplyBugProduct.DSFile = plMultiChoiceFiles1._DataSource;
                        if (!DAReplyBugProduct.Instance.Update(doReplyBugProduct))
                            ErrorMsg.ErrorSave(this);
                        else
                        {
                            AfterAddReplyIssueSuccessfully(doReplyBugProduct);
                            //Update status of issue if changed.
                            DABugProduct.UpdateStatusIssue(doBugProduct.ID, Tinh_trang._getSelectedID());
                            if (AfterUpdateStatusOfIssue != null) AfterUpdateStatusOfIssue(Tinh_trang._getSelectedID(),null);
                            HelpXtraForm.CloseFormNoConfirm(this);
                        }
                    }
                    else if (IsAdd == false && AfterUpdateReplyIssueSuccessfully == null)
                    {
                        title = "Có vấn đề vừa được cập nhật!";
                        doBugProduct.DSFile = plMultiChoiceFiles1._DataSource;
                        if (!DABugProduct.Instance.Update(doBugProduct))
                            ErrorMsg.ErrorSave(this);
                        else
                        {
                            if (AfterAddIssueSuccessfully != null) AfterAddIssueSuccessfully(doBugProduct);
                            if (AfterUpdateIssueSuccessfully != null) AfterUpdateIssueSuccessfully(doBugProduct);
                            if (AfterUpdateStatusOfIssue != null) AfterUpdateStatusOfIssue(Tinh_trang._getSelectedID(), new object[]{
                                loaiVanDe._getSelectedID(),memoVanDe.Text,Tinh_trang._getSelectedID()
                                ,HelpDB.getDatabase().GetSystemCurrentDateTime(),NguoiNhan._SelectedStrIDs});
                            HelpXtraForm.CloseFormNoConfirm(this);
                        }
                    }
                    else if (IsAdd == false && AfterUpdateReplyIssueSuccessfully != null)
                    {
                        title = "Có phản hồi vấn đề vừa được cập nhật!";
                        doReplyBugProduct = new DOReplyBugProduct(_ID_Bug_Reply, _ID_Bug
                            , FrameworkParams.currentUser.employee_id, NguoiNhan._SelectedStrIDs, DateTime.Now,
                            NoiDung._getValue());
                        doReplyBugProduct.DSFile = plMultiChoiceFiles1._DataSource;
                        if (!DAReplyBugProduct.Instance.Update(doReplyBugProduct))
                            ErrorMsg.ErrorSave(this);
                        else
                        {
                            AfterUpdateReplyIssueSuccessfully(doReplyBugProduct);
                            //Update status of issue if changed.
                            DABugProduct.UpdateStatusIssue(doBugProduct.ID, Tinh_trang._getSelectedID());
                            if (AfterUpdateStatusOfIssue != null) AfterUpdateStatusOfIssue(Tinh_trang._getSelectedID(), null);
                            HelpXtraForm.CloseFormNoConfirm(this);
                        }
                    }

                    if (lstUser.Count > 0)
                    {
                        AddressList To = new AddressList();

                        title = HelpStringBuilder.GetTitleMailNewPageper(title);
                        StringBuilder Subject = new StringBuilder();
                        IDataReader reader = FWDBService.LoadRecord("DM_LOAI_VAN_DE", "ID", this.loaiVanDe._getSelectedID());
                        using (reader)
                        {
                            if (reader.Read())
                            {
                                Subject.Append(string.Format(PLConst.DES_MAIL_VAN_DE, memoVanDe.Text, reader["NAME"].ToString(), lblNguoiGui.Text, NoiDung.richEditControl.HtmlText));
                            }
                        }
                        if (!lstUser.Contains(FrameworkParams.currentUser.employee_id))
                            lstUser.Add(FrameworkParams.currentUser.employee_id);
                        To = HelpZPLOEmail.GetAddressList(lstUser.ToArray());
                        HelpZPLOEmail.SendSmartHost(
                            HelpAutoOpenForm.GeneratingCodeFromForm(this, _ID_Bug),
                            title, null, To, null, null, Subject.ToString(), "");
                    }
                }
                else
                {
                    HelpMsgBox.ShowNotificationMessage("Vui lòng vào thông tin \"Mô tả vấn đề\"!");
                    return;
                }
            }
        }
Example #14
0
		/// <summary>
		/// Creates simple mime message with attachments.
		/// </summary>
		/// <param name="from">Header field From: value.</param>
		/// <param name="to">Header field To: value.</param>
		/// <param name="subject">Header field Subject: value.</param>
		/// <param name="bodyText">Body text of message. NOTE: Pass null is body text isn't wanted.</param>
		/// <param name="bodyHtml">Body HTML text of message. NOTE: Pass null is body HTML text isn't wanted.</param>
		/// <param name="attachmentFileNames">Attachment file names. Pass null if no attachments. NOTE: File name must contain full path to file, for example: c:\test.pdf.</param>
		/// <returns></returns>
		public static Mime CreateSimple(AddressList from,AddressList to,string subject,string bodyText,string bodyHtml,string[] attachmentFileNames)
		{
			Mime m = new Mime();

			MimeEntity mainEntity = m.MainEntity;
			mainEntity.From = from;
			mainEntity.To = to;
			mainEntity.Subject = subject;

			// There are no atachments
			if(attachmentFileNames == null || attachmentFileNames.Length == 0){
				// If bodyText and bodyHtml both specified
				if(bodyText != null && bodyHtml != null){
					mainEntity.ContentType = MediaType_enum.Multipart_alternative;

					MimeEntity textEntity = mainEntity.ChildEntities.Add();
					textEntity.ContentType = MediaType_enum.Text_plain;
					textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
					textEntity.DataText = bodyText;

					MimeEntity textHtmlEntity = mainEntity.ChildEntities.Add();
					textHtmlEntity.ContentType = MediaType_enum.Text_html;
					textHtmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
					textHtmlEntity.DataText = bodyHtml;
				}
				// There is only body text
				else if(bodyText != null){
					MimeEntity textEntity = mainEntity;
					textEntity.ContentType = MediaType_enum.Text_plain;
					textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
					textEntity.DataText = bodyText;
				}
				// There is only body html text
				else if(bodyHtml != null){
					MimeEntity textHtmlEntity = mainEntity;
					textHtmlEntity.ContentType = MediaType_enum.Text_html;
					textHtmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
					textHtmlEntity.DataText = bodyHtml;
				}
			}
			// There are attachments
			else{				
				mainEntity.ContentType = MediaType_enum.Multipart_mixed;

				// If bodyText and bodyHtml both specified
				if(bodyText != null && bodyHtml != null){
					MimeEntity multiPartAlternativeEntity = mainEntity.ChildEntities.Add();
					multiPartAlternativeEntity.ContentType = MediaType_enum.Multipart_alternative;

					MimeEntity textEntity = multiPartAlternativeEntity.ChildEntities.Add();
					textEntity.ContentType = MediaType_enum.Text_plain;
					textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
					textEntity.DataText = bodyText;

					MimeEntity textHtmlEntity = multiPartAlternativeEntity.ChildEntities.Add();
					textHtmlEntity.ContentType = MediaType_enum.Text_html;
					textHtmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
					textHtmlEntity.DataText = bodyHtml;
				}
				// There is only body text
				else if(bodyText != null){
					MimeEntity textEntity = mainEntity.ChildEntities.Add();
					textEntity.ContentType = MediaType_enum.Text_plain;
					textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
					textEntity.DataText = bodyText;
				}
				// There is only body html text
				else if(bodyHtml != null){
					MimeEntity textHtmlEntity = mainEntity.ChildEntities.Add();
					textHtmlEntity.ContentType = MediaType_enum.Text_html;
					textHtmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
					textHtmlEntity.DataText = bodyHtml;
				}

				foreach(string fileName in attachmentFileNames){
					MimeEntity attachmentEntity = mainEntity.ChildEntities.Add();
					attachmentEntity.ContentType = MediaType_enum.Application_octet_stream;
					attachmentEntity.ContentDisposition = ContentDisposition_enum.Attachment;
					attachmentEntity.ContentTransferEncoding = ContentTransferEncoding_enum.Base64;
					attachmentEntity.ContentDisposition_FileName = Core.GetFileNameFromPath(fileName);
					attachmentEntity.DataFromFile(fileName);
				}
			}

			return m;
		}
 private AddressList GetAddressList(long IDNhanVien)
 {
     QueryBuilder query = new QueryBuilder(@"SELECT e.NAME,e.email from  DM_NHAN_VIEN e WHERE 1=1");
     query.addID("e.ID", IDNhanVien);
     DataSet dsTo = HelpDB.getDatabase().LoadDataSet(query, "CAT");
     AddressList to = new AddressList();
     foreach (DataRow row in dsTo.Tables[0].Rows)
     {
         if (row["EMAIL"].ToString() == "") continue;
         to.Add(new MailboxAddress(row["NAME"].ToString(), row["EMAIL"].ToString()));
     }
     return to;
 }
        /// <summary>
        /// Gửi thông báo duyệt tin trên Tin tức (KHÔNG DÙNG NỮA)
        /// </summary>
        private bool _SendThongBao(DataRow row,string STATUS)
        {
            ///Thông tin SMTP
            DOServer o = DAServer.Instance.LoadAll(1);
            ///1.Nội dung
            DOTinTuc newPegeper = DATinTuc.Instance.LoadAll(HelpNumber.ParseInt64(row["ID"]));
            AddressList To = new AddressList();
            string temp = "";
            switch (STATUS) {
                case "DUYET":
                    temp = "Có 1 tin mới được cập nhật.";
                    //Gửi đến tất cả các nhân viên
                    To = PLHelpMail.GetAddressList(new long[] {});
                    break;
                case "ADD":
                    temp = "Có 1 tin tạo mới đang chờ duyệt.";
                    //Gửi đến những người có quyền duyệt
                    To = PLHelpMail.GetAddressList(new long[] { });
                    break;
                case "EDIT":
                    temp = "Có 1 tin chỉnh sửa đang chờ duyệt.";
                    //Gửi đến những người có quyền duyệt
                    To = PLHelpMail.GetAddressList(new long[] { });
                    break;
                case "KHONG_DUYET":
                    temp = "Có 1 tin không được duyệt.";
                    //Gửi đến người tạo tin
                    To = PLHelpMail.GetAddressList(new long[] { newPegeper.NGUOI_CAP_NHAT });
                    break;
                case "CHO_DUYET":
                    //Gửi đến người đã tạo tin
                    To = PLHelpMail.GetAddressList(new long[] { newPegeper.NGUOI_CAP_NHAT });
                    break;
            }
            string Title = HelpStringBuilder.GetTitleMailNewPageper(temp);

            string NhomTin = HelpDB.getDatabase().LoadDataSet(new QueryBuilder(
               @"SELECT * FROM DM_NHOM_TIN_TUC WHERE ID=" + newPegeper.NHOM_TIN +" AND 1=1")).Tables[0].Rows[0]["NAME"].ToString();
            string Subject = HelpStringBuilder.GetDesMailNewPageper(DMFWNhanVien.GetFullName(newPegeper.NGUOI_CAP_NHAT) , newPegeper.NGAY_CAP_NHAT.ToString() ,NhomTin,newPegeper.TIEU_DE);
            ///3.Gửi mail
            return PLHelpMail._SendMail(o.SMTP, 25,"", Title, o.NAME,o.EMAIL,o.PASS, To, null, null, Subject, "");
        }
        private void m_pOk_Click(object sender, EventArgs e)
        {
            AddressList from = new AddressList();
            from.Parse(m_pFrom.Text);
            AddressList to = new AddressList();
            to.Parse(m_pTo.Text);
            Mime m = Mime.CreateSimple(from,to,m_pSubject.Text,m_pBodyText.Text,null);
            m_Message = m.ToStringData();

            this.DialogResult = DialogResult.OK;
        }
Example #18
0
 private void GuiThongBaoLuong(string subject, string fileName, long idNguoiNhan)
 {
     Mime message = new Mime();
     MimeEntity texts_enity = null;
     MimeEntity attachments_entity = null;
     message.MainEntity.ContentType = MediaType_enum.Multipart_mixed;
     texts_enity = message.MainEntity.ChildEntities.Add();
     texts_enity.ContentType = MediaType_enum.Multipart_alternative;
     attachments_entity = message.MainEntity;
     //File đính kèm
     MimeEntity attachment_entity = attachments_entity.ChildEntities.Add();
     attachment_entity.ContentType = MediaType_enum.Application_octet_stream;
     attachment_entity.ContentTransferEncoding = ContentTransferEncoding_enum.Base64;
     attachment_entity.ContentDisposition = ContentDisposition_enum.Attachment;
     attachment_entity.ContentDisposition_FileName = Path.GetFileName(fileName);
     attachment_entity.Data = File.ReadAllBytes(fileName);
     //Thông tin mail
     AddressList to = new AddressList();
     to.Add(new MailboxAddress("PL-Office", "*****@*****.**"));
     message.MainEntity.From = to;
     message.MainEntity.To = HelpZPLOEmail.GetAddressList(new long[] { idNguoiNhan });
     message.MainEntity.Subject = subject;
     message.MainEntity.Bcc = to;
     //Nội dung
     MimeEntity text_entity = texts_enity.ChildEntities.Add();
     text_entity.ContentType = MediaType_enum.Text_plain;
     text_entity.ContentType_CharSet = "utf-8";
     text_entity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
     text_entity.DataText = "Vui lòng xem chi tiết lương trong tập tin đính kèm email này.";
     //Gửi mail
     SmtpClientEx.QuickSendSmartHost("protocolvn.net", 25, "", message);
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            List<long> lstUser = new List<long>(NguoiNhanMail._SelectedIDs);
            string title = "";
            //Thêm người hỗ trợ vào danh sách gửi mail trong trường hợp ko chọn
            foreach (long id in NguoiNhan._SelectedIDs)
                if (!lstUser.Contains(id))
                    lstUser.Add(id);
            if (!Error_Data()) {
                GetDOData();
                if (DAHomThuGopY.I.Update(Data_Obj)){
                    title = "Có thư góp ý mới vừa được cập nhật";
                    HelpXtraForm.CloseFormNoConfirm(this);
                    if (RefreshDataAfterUpdate != null) RefreshDataAfterUpdate(Data_Obj);

                    /////////gửi mail
                    if (lstUser.Count > 0)
                    {
                        AddressList To = new AddressList();

                        title = HelpStringBuilder.GetTitleMailNewPageper(title);
                        StringBuilder Subject = new StringBuilder();
                        IDataReader reader = FWDBService.LoadRecord("HOM_THU_GOP_Y", "ID", Data_Obj.ID);
                        using (reader)
                        {
                            if (reader.Read())
                            {
                                Subject.Append(string.Format(PLConst.DES_MAIL_HTGY, txtTieude.Text, lblNguoiCapNhat.Text, NoiDung.richEditControl.HtmlText));
                            }
                        }
                        if (!lstUser.Contains(FrameworkParams.currentUser.employee_id))
                            lstUser.Add(FrameworkParams.currentUser.employee_id);
                        To = HelpZPLOEmail.GetAddressList(lstUser.ToArray());
                        HelpZPLOEmail.SendSmartHost(
                            HelpAutoOpenForm.GeneratingCodeFromForm(this, Data_Obj.ID),
                            title, null, To, null, null, Subject.ToString(), "");
                    }
                }
                else ErrorMsg.ErrorSave(this);
            }
        }