Add() public method

Adds a new address to the end of the collection.
public Add ( Address address ) : void
address Address Address to add.
return void
        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 #2
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);
 }
        /// <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);
        }
 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;
 }
        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;
        }