Ejemplo n.º 1
0
        public void SendMail()
        {
            try
            {
                NotesSession ns = new NotesSessionClass();

                ns.Initialize(pwd);
                NotesDatabase ndb = ns.GetDatabase(serverName, nsfFile, false);

                NotesDocument doc = ndb.CreateDocument();
                doc.ReplaceItemValue("Form", "Memo");
                string[] sendtoString = mailTo.ToArray();
                doc.ReplaceItemValue("SendTo", sendtoString);
                doc.ReplaceItemValue("Subject", subject);
                NotesRichTextItem rt = doc.CreateRichTextItem("Body");
                rt.AppendText(body);

                if ((attFileName != null) && (attFileName.Count > 0))
                {
                    NotesRichTextItem item = doc.CreateRichTextItem("attachment");
                    foreach (string att in attFileName)
                    {
                        item.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, "", att, "attachment");
                    }
                }

                object obj = doc.GetItemValue("SendTo");
                doc.Send(false, ref obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Lotus Send E-Mail
        /// </summary>
        /// <param name="sendTo"></param>
        /// <param name="copyTo"></param>
        /// <param name="subject"></param>
        /// <param name="content"></param>
        /// Owner:Andy Gao 2011-08-22 09:32:50
        public static void LotusSendEMail(string[] sendTo, string[] copyTo, string subject, string content)
        {
            NotesSession ns = new NotesSession();

            ns.Initialize(lotusPassword);

            NotesDatabase ndb = ns.GetDatabase(lotusServer, lotusFile, false);

            NotesDocument doc = ndb.CreateDocument();

            doc.ReplaceItemValue(LOTUS_SENDTO, sendTo);
            doc.ReplaceItemValue(LOTUS_COPYTO, copyTo);
            doc.ReplaceItemValue(LOTUS_SUBJECT, subject);

            NotesRichTextItem rti = doc.CreateRichTextItem(LOTUS_BODY);

            rti.AppendText(content);

            object recipients = doc.GetItemValue(LOTUS_SENDTO);

            doc.Send(false, ref recipients);

            Marshal.ReleaseComObject(rti);
            Marshal.ReleaseComObject(doc);
            Marshal.ReleaseComObject(ndb);
            Marshal.ReleaseComObject(ns);

            rti = null;
            doc = null;
            ndb = null;
            ns  = null;
        }
Ejemplo n.º 3
0
        public DocumentModel(LotusNotesWrapper wrapper, NotesDocument document)
        {
            this.document = document;

            LoadEmailContent(wrapper);

            Authors         = ((IEnumerable)document.Authors).Cast <string>().ToArray();
            Created         = document.Created;
            EmbeddedObjects = document.EmbeddedObjects;
            HasEmbedded     = document.HasEmbedded;
            HttpURL         = document.HttpURL;
            IsDeleted       = document.IsDeleted;
            IsNewNote       = document.IsNewNote;
            IsProfile       = document.IsProfile;
            IsResponse      = document.IsResponse;
            IsSigned        = document.IsSigned;
            IsUIDocOpen     = document.IsUIDocOpen;
            IsValid         = document.IsValid;
            Key             = document.Key;
            LastAccessed    = document.LastAccessed;
            LastModified    = document.LastModified;
            NameOfProfile   = document.NameOfProfile;
            NoteID          = document.NoteID;
            NotesURL        = document.NotesURL;
            ParentView      = document.ParentView;
            Responses       = document.Responses;
            SentByAgent     = document.SentByAgent;
            Signer          = document.Signer;
            SignOnSend      = document.SignOnSend;
            Size            = document.Size;
            Unid            = document.UniversalID;
            IsEncrypted     = document.IsEncrypted;

            Items = new Lazy <DocumentItemModel[]>(() => GetItems(document));

            Subject = document.GetItemValue(ItemFieldNames.Subject)[0];
            From    = document.GetItemValue(ItemFieldNames.From).ToString();
            To      = ((IEnumerable)document.GetItemValue(ItemFieldNames.SendTo)).Cast <string>().ToArray();
            Cc      = ((IEnumerable)document.GetItemValue(ItemFieldNames.CopyTo)).Cast <string>().ToArray();
        }
Ejemplo n.º 4
0
        private CalendarEvent GetCallendarEvent(NotesDocument Current, int RepeatIndex)
        {
            CalendarEvent e = new CalendarEvent();
            try
            {

                e.Starts = (DateTime)((object[])Current.GetItemValue("StartDateTime"))[RepeatIndex];
                e.Ends = (DateTime)((object[])Current.GetItemValue("EndDateTime"))[RepeatIndex];
                e.Title = (string)((object[])Current.GetItemValue("Subject"))[0];
                e.Location = (string)((object[])Current.GetItemValue("Room"))[0] + " " +
                                (string)((object[])Current.GetItemValue("Location"))[0];
            }
            catch (Exception ex)
            {
               throw ex;
            }
            return e;
        }
Ejemplo n.º 5
0
        public string SendMail(MailBody mailBody, MailSettings mailSettings)
        {
            _MailBody = mailBody;
            InitSettings(mailSettings);

            Validation();
            NotesSession  ns;
            NotesDatabase ndb;

            try
            {
                ns = new NotesSession();
                ns.Initialize(_Password);
                //初始化NotesDatabase
                ndb = ns.GetDatabase(_SMTPHost, "names.nsf", false);

                NotesDocument doc = ndb.CreateDocument();

                doc.ReplaceItemValue("Form", "Memo");

                //收件人信息
                doc.ReplaceItemValue("SendTo", ConvertToString(_MailBody.MailTo));

                if (_MailBody.MailCc != null && _MailBody.MailCc.Count > 0)
                {
                    doc.ReplaceItemValue("CopyTo", ConvertToString(_MailBody.MailCc));
                }

                if (_MailBody.MailBcc != null && _MailBody.MailBcc.Count > 0)
                {
                    doc.ReplaceItemValue("BlindCopyTo", ConvertToString(_MailBody.MailBcc));
                }

                //邮件主题
                doc.ReplaceItemValue("Subject", _MailBody.Subject);

                //邮件正文
                if (_MailBody.IsHtmlBody)
                {
                    NotesStream body = ns.CreateStream();
                    body.WriteText(_MailBody.Body, EOL_TYPE.EOL_PLATFORM);
                    NotesMIMEEntity mime = doc.CreateMIMEEntity("Body");
                    mime.SetContentFromText(body, "text/HTML;charset=gb2312", MIME_ENCODING.ENC_NONE);
                    body.Truncate();
                }
                else
                {
                    NotesRichTextItem rt = doc.CreateRichTextItem("Body");
                    rt.AppendText(_MailBody.Body);
                }

                //NotesRichTextItem rt = doc.CreateRichTextItem("Body");
                //if (_MailBody.IsHtmlBody)
                //{
                //    NotesRichTextStyle richtextStyle = ns.CreateRichTextStyle();
                //    richtextStyle.PassThruHTML = 1;
                //    rt.AppendStyle(richtextStyle);
                //}
                //rt.AppendText(_MailBody.Body);

                //附件
                //if (_MailBody.MailAttachments != null)
                //{
                //    NotesRichTextItem attachment = doc.CreateRichTextItem("attachment");
                //    foreach (MailAttachment a in _MailBody.MailAttachments)
                //    {
                //        if (!string.IsNullOrEmpty(a.Location))
                //        {
                //            attachment.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, "", a.Location, "attachment");
                //        }
                //    }
                //}
                //发送邮件
                object obj = doc.GetItemValue("SendTo");
                doc.Send(false, ref obj);
                doc = null;
                return("");
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    HandleMailLogs(ex.Message + "内部错误信息为:null");
                }
                else
                {
                    HandleMailLogs(ex.Message + "内部错误信息为:" + ex.InnerException.Message);
                }
                return("发送邮件失败");
            }
            finally
            {
                ndb = null;
                ns  = null;
                RecordTheMail();
            }
        }
Ejemplo n.º 6
0
        private void bExportDocuments_Click(object sender, EventArgs ea)
        {
            if (treeView1.SelectedNode == null || treeView1.SelectedNode.Nodes.Count > 0)
            {
                MessageBox.Show("Select a database.");
                return;
            }
            int            total        = 0;
            long           startTicks   = 0;
            long           lastTicks    = 0;
            string         timeLeft     = "";
            string         timeElapsed  = "0:00:00";
            string         databasePath = treeView1.SelectedNode.Name;
            ProgressDialog pDialog      = new ProgressDialog();

            pDialog.Title = "Exporting Documents";
            #region Export Documents
            pDialog.DoWork += delegate(object dialog, DoWorkEventArgs e)
            {
                try
                {
                    //export documents
                    NotesSession nSession             = initSession(notesPassword);
                    Dictionary <string, Table> tables = new Dictionary <string, Table>();

                    NotesDatabase db;
                    if (onLocalComputer)
                    {
                        db = nSession.GetDatabase("", databasePath, false);
                    }
                    else
                    {
                        db = nSession.GetDatabase(notesServer + "//" + notesDomain, databasePath, false);
                    }
                    //get all documents
                    total = db.AllDocuments.Count;
                    NotesDocumentCollection allDocuments = db.AllDocuments;
                    NotesDocument           doc          = allDocuments.GetFirstDocument();
                    startTicks = DateTime.Now.Ticks;
                    for (int i = 0; i < total; i++)
                    {
                        //check if cancelled
                        if (pDialog.IsCancelled)
                        {
                            e.Cancel = true;
                            return;
                        }
                        if (doc.HasItem("Form") && (string)doc.GetItemValue("Form")[0] != "")
                        {
                            //get form
                            string form = (string)doc.GetItemValue("Form")[0];

                            if (!tables.ContainsKey(form))
                            {
                                tables.Add(form, new Table(form));
                            }
                            int row = tables[form].AddRow();
                            //get fields
                            //set multiple values
                            foreach (NotesItem item in doc.Items)
                            {
                                //check if cancelled
                                if (pDialog.IsCancelled)
                                {
                                    e.Cancel = true;
                                    return;
                                }
                                string field = item.Name;
                                //exclude fields that start with $ and the Form field and Readers field
                                if (field == null || excludeField.IsMatch(field))
                                {
                                    continue;
                                }
                                string type = "";
                                switch (item.type)
                                {//TODO: get more types
                                case IT_TYPE.NUMBERS:
                                    type = "decimal(20,10)";
                                    break;

                                case IT_TYPE.DATETIMES:
                                    type = "datetime";
                                    break;

                                default:
                                    type = "text";
                                    break;
                                }
                                object values   = item.Values;
                                bool   multiple = item.Values.Length > 1;

                                if (!tables[form].Columns.ContainsKey(field))
                                {
                                    tables[form].Columns.Add(field, new Column(field, type));
                                }

                                if (multiple && !tables[form].Columns[field].MultipleValues)
                                {
                                    tables[form].Columns[field].MultipleValues = multiple;
                                }

                                if (!tables[form].Columns[field].Values.ContainsKey(row))
                                {
                                    tables[form].Columns[field].Values.Add(row, values);
                                }
                                else
                                {
                                    int j = 1;
                                    while (tables[form].Columns.ContainsKey(field + j) && tables[form].Columns[field + j].Values.ContainsKey(row))
                                    {
                                        j++;
                                    }

                                    field += j;

                                    if (!tables[form].Columns.ContainsKey(field))
                                    {
                                        tables[form].Columns.Add(field, new Column(field, type));
                                    }

                                    if (multiple && !tables[form].Columns[field].MultipleValues)
                                    {
                                        tables[form].Columns[field].MultipleValues = multiple;
                                    }

                                    tables[form].Columns[field].Values.Add(row, values);
                                }
                            }
                        }
                        //update progress
                        pDialog.ReportProgress(i, "Parsing Documents");
                        doc = allDocuments.GetNextDocument(doc);
                    }
                    //add tables for columns with multiple values
                    Dictionary <string, Table> newTables = new Dictionary <string, Table>(tables.Count);
                    lastTicks  = 0;
                    startTicks = DateTime.Now.Ticks;
                    total      = tables.Count;
                    int count = 0;
                    foreach (Table table in tables.Values)
                    {
                        //check if cancelled
                        if (pDialog.IsCancelled)
                        {
                            e.Cancel = true;
                            return;
                        }
                        pDialog.ReportProgress(++count, "Formatting Tables");
                        Dictionary <string, Column> columns = new Dictionary <string, Column>(table.Columns);
                        foreach (Column column in columns.Values)
                        {
                            if (column.MultipleValues)
                            {
                                string tableName = table.Name + "_" + column.Name;
                                Table  newTable  = new Table(tableName, table.Name);
                                Column values    = new Column(column.Name, column.Type);
                                Column ids       = new Column(table.Name + "id", "int");
                                foreach (KeyValuePair <int, object> cell in column.Values)
                                {
                                    //check if cancelled
                                    if (pDialog.IsCancelled)
                                    {
                                        e.Cancel = true;
                                        return;
                                    }
                                    int      id = cell.Key;
                                    object[] valueArray;
                                    if (cell.Value.GetType().IsArray)
                                    {
                                        valueArray = (object[])cell.Value;
                                    }
                                    else
                                    {
                                        valueArray = new object[] { cell.Value };
                                    }
                                    foreach (object value in valueArray)
                                    {
                                        //check if cancelled
                                        if (pDialog.IsCancelled)
                                        {
                                            e.Cancel = true;
                                            return;
                                        }
                                        int row = newTable.AddRow();
                                        ids.Values.Add(row, id);
                                        values.Values.Add(row, value);
                                    }
                                }
                                newTable.Columns.Add(table.Name + "id", ids);
                                newTable.Columns.Add(column.Name, values);
                                newTables.Add(tableName, newTable);
                                table.Columns.Remove(column.Name);
                            }
                            else
                            {
                                Dictionary <int, object> values = new Dictionary <int, object>(column.Values);
                                foreach (KeyValuePair <int, object> cell in values)
                                {
                                    //check if cancelled
                                    if (pDialog.IsCancelled)
                                    {
                                        e.Cancel = true;
                                        return;
                                    }
                                    int    id = cell.Key;
                                    object value;
                                    if (cell.Value.GetType().IsArray)
                                    {
                                        if (((object[])cell.Value).Length > 0)
                                        {
                                            value = ((object[])cell.Value)[0];
                                        }
                                        else
                                        {
                                            value = null;
                                        }
                                    }
                                    else
                                    {
                                        value = cell.Value;
                                    }
                                    column.Values[id] = value;
                                }
                            }
                        }
                        newTables.Add(table.Name, table);
                    }
                    //format to sql
                    total = newTables.Count;
                    bool complete = false;
                    do
                    {
                        lastTicks = 0;
                        count     = 0;
                        DialogResult result = DialogResult.Cancel;
                        Invoke((MethodInvoker) delegate() { result = MessageBox.Show(pDialog.Window, "Do you want to export to a MySQL server?", "Export to a server?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); });
                        if (result == DialogResult.Yes)
                        {
                            InputBox input = null;
                            Invoke((MethodInvoker) delegate() { input = InputBox.Show(pDialog.Window, "SQL server info?", new InputBoxItem[] { new InputBoxItem("Server", mysqlServer), new InputBoxItem("Database", mysqlDatabase), new InputBoxItem("Username", mysqlUsername), new InputBoxItem("Password", mysqlPassword, true), new InputBoxItem("Number of rows per INSERT", mysqlNumRowsPerInsert.ToString()) }, InputBoxButtons.OKCancel); });
                            if (input.Result == InputBoxResult.OK)
                            {
                                mysqlServer   = input.Items["Server"];
                                mysqlDatabase = input.Items["Database"];
                                mysqlUsername = input.Items["Username"];
                                mysqlPassword = input.Items["Password"];
                                int.TryParse(input.Items["Number of rows per INSERT"], out mysqlNumRowsPerInsert);

                                MySqlConnection conn = new MySqlConnection("SERVER=" + mysqlServer + ";USERNAME="******";PASSWORD="******";");

                                try
                                {
                                    startTicks = DateTime.Now.Ticks;
                                    conn.Open();

                                    MySqlCommand command = conn.CreateCommand();
                                    command.CommandText = createDatabase(mysqlDatabase);

                                    command.ExecuteNonQuery();
                                    foreach (Table table in newTables.Values)
                                    {
                                        //check if cancelled
                                        if (pDialog.IsCancelled)
                                        {
                                            e.Cancel = true;
                                            return;
                                        }
                                        pDialog.ReportProgress(++count, "Inserting SQL");
                                        if (table.Columns.Count > 0)
                                        {
                                            command.CommandText = createTable(table);
                                            command.ExecuteNonQuery();
                                            List <string> rows = insertTableRows(table);
                                            for (int i = 0; i < rows.Count; i += mysqlNumRowsPerInsert)
                                            {
                                                command.CommandText  = beginInsertTable(table);
                                                command.CommandText += String.Join(",", rows.GetRange(i, Math.Min(rows.Count - i, mysqlNumRowsPerInsert))) + ";\n";
                                                command.CommandText += endInsertTable(table);
                                                command.ExecuteNonQuery();
                                                pDialog.ReportProgress(count, "Inserting SQL");
                                            }
                                        }
                                    }
                                    command.CommandText = restoreVariables();
                                    command.ExecuteNonQuery();
                                    complete = true;
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message);
                                }
                                finally
                                {
                                    conn.Close();
                                }
                            }
                        }
                        else if (result == DialogResult.No)
                        {
                            saveFileDialog1.FileName = "export.sql";
                            result = DialogResult.Cancel;
                            Invoke((MethodInvoker) delegate() { result = saveFileDialog1.ShowDialog(pDialog.Window); });
                            if (result == DialogResult.OK)
                            {
                                InputBox input = null;
                                Invoke((MethodInvoker) delegate() { input = InputBox.Show(pDialog.Window, "Database name?", "Database Name", mysqlDatabase, InputBoxButtons.OKCancel); });
                                if (input.Result == InputBoxResult.OK)
                                {
                                    mysqlDatabase = input.Items["Database Name"];
                                    StreamWriter file = new StreamWriter(saveFileDialog1.FileName, false);
                                    try
                                    {
                                        startTicks = DateTime.Now.Ticks;
                                        file.WriteLine(createDatabase(mysqlDatabase));
                                        foreach (Table table in newTables.Values)
                                        {
                                            //check if cancelled
                                            if (pDialog.IsCancelled)
                                            {
                                                e.Cancel = true;
                                                return;
                                            }
                                            pDialog.ReportProgress(++count, "Formatting SQL");
                                            if (table.Columns.Count > 0)
                                            {
                                                file.WriteLine(createTable(table));
                                                file.WriteLine(beginInsertTable(table));
                                                file.WriteLine(String.Join(",", insertTableRows(table)) + ";");
                                                file.WriteLine(endInsertTable(table));
                                            }
                                        }
                                        file.WriteLine(restoreVariables());
                                        complete = true;
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show(ex.ToString());
                                    }
                                    finally
                                    {
                                        file.Close();
                                    }
                                }
                            }
                        }
                        else
                        {
                            e.Cancel = true;
                            return;
                        }
                    } while (!complete);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    e.Cancel = true;
                }
            };
            #endregion
            pDialog.ProgressChanged += delegate(object dialog, ProgressChangedEventArgs e)
            {
                if (lastTicks == 0)
                {
                    lastTicks = DateTime.Now.Ticks;
                    timeLeft  = "Calculating...";
                }
                else if (e.ProgressPercentage > 0 && DateTime.Now.Ticks > lastTicks + 10000000)
                {
                    lastTicks = DateTime.Now.Ticks;

                    long ticksPassed     = lastTicks - startTicks;
                    long thingsCompleted = e.ProgressPercentage;
                    long thingsLeft      = total - thingsCompleted;

                    long ticks = thingsLeft * ticksPassed / thingsCompleted;

                    timeLeft    = ticksToString(ticks);
                    timeElapsed = ticksToString(ticksPassed);
                }

                pDialog.Message = e.UserState.ToString() + ": " + e.ProgressPercentage + "/" + total + " Time Remaining: " + timeLeft + " Time Elapsed: " + timeElapsed;
                if (total == 0)
                {
                    pDialog.Progress = 0;
                }
                else
                {
                    pDialog.Progress = (100 * e.ProgressPercentage / total) % 101;
                }
            };
            pDialog.Completed += delegate(object dialog, RunWorkerCompletedEventArgs e)
            {
                if (!e.Cancelled)
                {
                    MessageBox.Show("Completed Successfully");
                }
            };
            pDialog.Run();
        }
Ejemplo n.º 7
0
        public Program()
        {
            ns = new NotesSession();
            ns.Initialize("password");

            string mailServer = ns.GetEnvironmentString("MailServer", true);
            string mailFile   = ns.GetEnvironmentString("MailFile", true);
            string userName   = ns.UserName;

            System.Console.WriteLine($"mailServer: {mailServer}");
            System.Console.WriteLine($"mailFile: {mailFile}");
            System.Console.WriteLine($"userName: {userName}");

            StringBuilder fullpathName = new StringBuilder(512);

            OSPathNetConstruct(null, mailServer, mailFile, fullpathName);
            System.Console.WriteLine($"fullpathName: {fullpathName.ToString()}");

            HANDLE hNotesDB;
            HANDLE hUnreadListTable;

            NSFDbOpen(fullpathName.ToString(), out hNotesDB);
            System.Console.WriteLine($"hNotesDB: {hNotesDB.ToString()}");

            NSFDbGetUnreadNoteTable(hNotesDB, userName, (ushort)userName.Length, true, out hUnreadListTable);
            System.Console.WriteLine($"hUnreadListTable: {hUnreadListTable.ToString()}");
            db = ns.GetDatabase(mailServer, mailFile, false);

            int    numUnreadMail = 0;
            bool   first         = true;
            HANDLE id;

            while (true)
            {
                numUnreadMail = 0; first = true;
                while (IDScan(hUnreadListTable, first, out id))
                {
                    doc = db.GetDocumentByID(id.ToString("X"));
                    string subject = (string)((object[])doc.GetItemValue("Subject"))[0];
                    string sender  = (string)((object[])doc.GetItemValue("From"))[0];
                    if (!sender.Equals(""))
                    {
                        System.Console.WriteLine($"   Doc: {subject} / *{sender}*");
                        if (!sender.Equals(userName))
                        {
                            numUnreadMail++;
                        }
                    }
                    first = false;
                }
                //numUnreadMail -= 3;
                System.Console.WriteLine($"Unread mail: {numUnreadMail.ToString()}");
                System.Threading.Thread.Sleep(3000);
                NSFDbUpdateUnread(hNotesDB, hUnreadListTable);
            }
            IDDestroyTable(hUnreadListTable);
            NSFDbClose(hNotesDB);

            /*
             * db = ns.GetDatabase(mailServer, mailFile, false);
             *
             * NotesView inbox = db.GetView("($Inbox)");
             * doc = inbox.GetFirstDocument();
             * System.Console.WriteLine($"Notes database: /{db.ToString()}");
             *
             * // NotesViewEntryCollection vc = inbox.GetAllUnreadEntries();
             *
             * while (doc != null)
             * {
             *  System.DateTime lastAccessed = doc.LastAccessed;
             *  System.DateTime lastModified = doc.LastModified;
             *  System.DateTime created = doc.Created;
             *
             *  //if ( (lastAccessed.Subtract(lastModified)).TotalSeconds==(double)0.0 && (created.Subtract(lastModified)).TotalSeconds<(double)60.0 )
             *  if (lastAccessed.CompareTo(lastModified) < 0)
             *
             *  {
             *      string subject = (string)((object[])doc.GetItemValue("Subject"))[0];
             *      System.Console.WriteLine($"LastAccessed: {doc.LastAccessed} | LastModified: {doc.LastModified} | Created: {doc.Created} | Subject: {subject}");
             *  }
             *  doc = inbox.GetNextDocument(doc);
             * }
             *
             * db = null;
             * ns = null;
             *
             */

            System.Console.WriteLine("Hello world!");
            System.Console.ReadLine();      // as pause
        }
Ejemplo n.º 8
0
        public void Pub()
        {
            try
            {
                NotesSession ns = new NotesSessionClass();
                ns.Initialize(pwd);
                NotesDatabase ndb = ns.GetDatabase(serverName, nsfFile, false);

                NotesDocument doc = ndb.CreateDocument();

                doc.ReplaceItemValue("Form", "中央气象台产品记录");

                doc.ReplaceItemValue("dbname_11", "juece.nsf");
                doc.ReplaceItemValue("dbname_12", "juece.nsf");
                doc.ReplaceItemValue("dbname_13", "juece.nsf");
                doc.ReplaceItemValue("dbname_21", "juece.nsf");
                doc.ReplaceItemValue("dbname_22", "juece.nsf");
                doc.ReplaceItemValue("dbname_222", "juece.nsf");
                doc.ReplaceItemValue("dbname_23", "juece.nsf");
                doc.ReplaceItemValue("dbname_24", "juece.nsf");
                doc.ReplaceItemValue("dbname_30", "juece.nsf");
                doc.ReplaceItemValue("doctype", "OCX");
                doc.ReplaceItemValue("Encrypt", "0");

                doc.ReplaceItemValue("img", "");
                doc.ReplaceItemValue("issuetime", this.dateNum);
                doc.ReplaceItemValue("SendTo", "CMA决策");
                doc.ReplaceItemValue("SendTobyHub", "各省气象信息共享数据库");
                doc.ReplaceItemValue("sendOk", "0");
                doc.ReplaceItemValue("role", "周军");
                doc.ReplaceItemValue("role_1", "短期科");

                doc.ReplaceItemValue("标题域", this.Title);
                doc.ReplaceItemValue("标题域_1", this.Title);
                doc.ReplaceItemValue("部委", "0");
                doc.ReplaceItemValue("草稿", "0");
                doc.ReplaceItemValue("产品", "天气预报");
                doc.ReplaceItemValue("产品_1", "天气预报");
                doc.ReplaceItemValue("发布单位", "国家气象中心");
                doc.ReplaceItemValue("发布单位_1", "中央气象台");
                doc.ReplaceItemValue("发布单位_1_1", "中央气象台");
                doc.ReplaceItemValue("发布单位_2", "国家气象中心");
                doc.ReplaceItemValue("发布单位_e", "qxt");
                doc.ReplaceItemValue("发布时间", this.dateNum);
                doc.ReplaceItemValue("发布时间_1", this.datePy);
                doc.ReplaceItemValue("发布时间_2", this.dateNum);
                //doc.ReplaceItemValue("内容", this.Content);
                doc.ReplaceItemValue("日期1", this.dateNum);
                doc.ReplaceItemValue("状态", "1");

                if ((attFileName != null) && (attFileName.Count > 0))
                {
                    NotesRichTextItem item = doc.CreateRichTextItem("attachment");
                    foreach (string att in attFileName)
                    {
                        item.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, "", att, "attachment");
                        doc.ReplaceItemValue("fname", System.IO.Path.GetFileName(att));
                    }
                }

                doc.ComputeWithForm(true, false);
                object obj = doc.GetItemValue("SendTo");
                doc.Send(false, ref obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 转发/回复信件
        /// </summary>
        /// <param name="pSupervisors">抄送人</param>
        /// <param name="pSendSecret">密送人</param>
        /// <param name="strNotesUID">原NotesID</param>
        /// <param name="strMailContent">内容</param>
        /// <returns></returns>
        public bool RelayMailInfo(object pSupervisors, object pSendSecret, string strNotesUID, string strMailContent)
        {
            bool          bResult         = false;
            NotesView     pParentView     = null;
            NotesDocument pParentDocument = null;

            try
            {
                if (this._strDataBase == "names.nsf")
                {
                    this.pNotesDatabase = this._pNotesSession.GetDatabase(this._strDomain, this._strDataBase, false);
                }

                if (this.pNotesDatabase == null)
                {
                    throw new Exception("不能打开数据库:" + this._strDataBase);
                }

                pParentView     = this.pNotesDatabase.GetView("($inbox)");
                pParentDocument = pParentView.GetFirstDocument();

                while (pParentDocument != null)
                {
                    if (pParentDocument.UniversalID == strNotesUID)
                    {
                        NotesDocument pRelayDocument  = pParentDocument.CreateReplyMessage(false);
                        string        strPrincipal    = (((object[])pParentDocument.GetItemValue("Principal"))[0] == null) ? "N/A" : ((object[])pParentDocument.GetItemValue("Principal"))[0].ToString();
                        string        strRelaySubject = (((object[])pParentDocument.GetItemValue("Subject"))[0] == null) ? "N/A" : ((object[])pParentDocument.GetItemValue("Subject"))[0].ToString();

                        pParentDocument.ReplaceItemValue("Form", "Reply");
                        pParentDocument.ReplaceItemValue("CopyTo", pSupervisors);     //抄送
                        pParentDocument.ReplaceItemValue("BlindCopyTo", pSendSecret); //密送
                        pParentDocument.ReplaceItemValue("Subject", "回复:" + strRelaySubject);
                        pParentDocument.ReplaceItemValue("PostedDate", DateTime.Now.ToString());
                        pParentDocument.ReplaceItemValue("Principal", "CN=netadmin/OU=网管部/OU=产品运营中心/O=runstar");
                        pParentDocument.ReplaceItemValue("Body", "");
                        pParentDocument.ReplaceItemValue("SSM_Agent", strNotesUID);

                        if (pParentDocument.HasItem("Reader"))
                        {
                            pParentDocument.ReplaceItemValue("Reader", "NO");
                        }

                        NotesRichTextItem pOldItem = (NotesRichTextItem)pParentDocument.GetFirstItem("Body");
                        pOldItem.AppendText(strMailContent);
                        pOldItem.AddNewLine(5, false);
                        pOldItem.AppendRTItem((NotesRichTextItem)pRelayDocument.GetFirstItem("Body"));

                        object pSendOwner = strPrincipal;//"孙露"
                        pParentDocument.Send(false, ref pSendOwner);

                        bResult = true;

                        Marshal.ReleaseComObject(pOldItem);
                        Marshal.ReleaseComObject(pRelayDocument);

                        pOldItem       = null;
                        pRelayDocument = null;
                        break;
                    }
                    else
                    {
                        bResult = false;

                        this.strMessage = "不能找到原始信件,原信件可能已删除,请新建一封信的信件给接收人!";
                    }

                    pParentDocument = pParentView.GetNextDocument(pParentDocument);
                }
            }
            catch (Exception ex)
            {
                this.strMessage = ex.Message;

                bResult = false;
            }
            finally
            {
                if (pParentDocument != null)
                {
                    Marshal.ReleaseComObject(pParentDocument);
                }

                if (pParentView != null)
                {
                    Marshal.ReleaseComObject(pParentView);
                }

                pParentDocument = null;
                pParentView     = null;
            }

            return(bResult);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 将超过指定时间的邮件移动到指定目录下
        /// </summary>
        /// <returns></returns>
        public bool MoveMailInfo()
        {
            bool          bResult       = false;
            NotesView     pMailView     = null;
            NotesDocument pMailDocument = null;

            try
            {
                if (this._strDataBase == "names.nsf")
                {
                    this.pNotesDatabase = this._pNotesSession.GetDatabase(this._strDomain, this._strDataBase, false);
                }

                if (null == this.pNotesDatabase)
                {
                    throw new Exception("不能打开数据库:" + this._strDataBase);
                }

                pMailView = this.pNotesDatabase.GetView("($inbox)");

                pMailDocument = pMailView.GetFirstDocument();

                DateTime NowTime = DateTime.Now.AddDays(-2);

                int MailCount = 0;

                for (int i = 0; i < pMailView.EntryCount; i++)
                {
                    if (null != pMailDocument)
                    {
                        DateTime MailTime    = Convert.ToDateTime(((object[])pMailDocument.GetItemValue("DeliveredDate"))[0].ToString());
                        string   str_subject = ((object[])pMailDocument.ColumnValues)[5].ToString();

                        if (NowTime > MailTime || 0 < str_subject.IndexOf("服务器正常", 0) || 0 < str_subject.IndexOf("服务器一切正常", 0))
                        {
                            pMailDocument.PutInFolder("超时邮件", false);

                            NotesDocument oldMailDocument = pMailDocument;
                            if (null != oldMailDocument)
                            {
                                oldMailDocument.RemoveFromFolder("($inbox)");
                            }
                            pMailDocument = pMailView.GetFirstDocument();
                            i             = -1;
                            MailCount++;
                        }
                        else
                        {
                            pMailDocument = pMailView.GetNextDocument(pMailDocument);
                        }
                    }
                }

                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("共移动了:" + MailCount);
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine("");

                bResult = true;
            }
            catch (Exception ex)
            {
                this.strMessage = ex.Message;
                Console.WriteLine(ex.Message);

                bResult = false;
            }
            finally
            {
                if (pMailDocument != null)
                {
                    Marshal.ReleaseComObject(pMailDocument);
                }

                if (pMailView != null)
                {
                    Marshal.ReleaseComObject(pMailView);
                }

                pMailDocument = null;
                pMailView     = null;
            }

            return(bResult);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 获取新信件
        /// </summary>
        /// <returns></returns>
        public bool GetMailInfo()
        {
            bool          bResult       = false;
            NotesView     pMailView     = null;
            NotesDocument pMailDocument = null;
            int           iCount        = 0;

            try
            {
                if (this._strDataBase == "names.nsf")
                {
                    this.pNotesDatabase = this._pNotesSession.GetDatabase(this._strDomain, this._strDataBase, false);
                }

                if (this.pNotesDatabase == null)
                {
                    throw new Exception("不能打开数据库:" + this._strDataBase);
                }

                pMailView = this.pNotesDatabase.GetView("($inbox)");

                pMailDocument = pMailView.GetFirstDocument();
                Console.WriteLine("共计:" + pMailView.EntryCount.ToString());

                CustomDataCollection pMailStruct = new CustomDataCollection(StructType.CUSTOMDATA);

                while (pMailDocument != null)
                {
                    if (((object[])pMailDocument.GetItemValue("Reader"))[0].ToString() != "YES")
                    {
                        string strPUID        = string.Empty;
                        string strSubject     = (((object[])pMailDocument.ColumnValues)[5] == null) ? "N/A" : ((object[])pMailDocument.ColumnValues)[5].ToString();
                        string strSupervisors = (((object[])pMailDocument.GetItemValue("CopyTo")).Length == 0) ? "N/A" : ((object[])pMailDocument.GetItemValue("CopyTo"))[0].ToString();
                        string strSendTo      = (((object[])pMailDocument.GetItemValue("SendTo")).Length == 0) ? "N/A" : ((object[])pMailDocument.GetItemValue("SendTo"))[0].ToString();

                        if (strSendTo != "N/A")
                        {
                            for (int i = 0; i < ((object[])pMailDocument.GetItemValue("SendTo")).Length; i++)
                            {
                                strSupervisors = strSupervisors + ";" + ((object[])pMailDocument.GetItemValue("SendTo"))[i].ToString();
                            }
                        }

                        if (strSupervisors != "N/A")
                        {
                            for (int i = 1; i < ((object[])pMailDocument.GetItemValue("CopyTo")).Length; i++)
                            {
                                strSupervisors = strSupervisors + ";" + ((object[])pMailDocument.GetItemValue("CopyTo"))[i].ToString();
                            }
                        }

                        string strBody = ((object[])pMailDocument.GetItemValue("Body"))[0].ToString();

                        if (((object[])pMailDocument.GetItemValue("SSM_Agent"))[0].ToString().Length != 0)
                        {
                            strPUID = ((object[])pMailDocument.GetItemValue("SSM_Agent"))[0].ToString();
                        }
                        else if (((object[])pMailDocument.GetItemValue("SSM_Agent"))[0].ToString().Length == 0 && pMailDocument.ParentDocumentUNID == null)
                        {
                            strPUID = "N/A";
                        }
                        else
                        {
                            strPUID = pMailDocument.ParentDocumentUNID;
                        }

                        /*
                         * if (pMailDocument.HasItem("SMS Agent"))
                         * {
                         *  strPUID = ((object[])pMailDocument.GetItemValue("SMS Agent"))[0].ToString();
                         * }
                         * else if (!pMailDocument.HasItem("SMS Agent") && pMailDocument.ParentDocumentUNID == null)
                         * {
                         *  strPUID = "N/A";
                         * }
                         * else
                         * {
                         *  strPUID = pMailDocument.ParentDocumentUNID;
                         * }
                         */

                        //剔除--服务器正常和服务器一切正常
                        if (strSubject.IndexOf("服务器正常", StringComparison.CurrentCulture) > 0 || strSubject.IndexOf("服务器一切正常", StringComparison.CurrentCulture) > 0)
                        {
                            if (pMailDocument.HasItem("Reader"))
                            {
                                pMailDocument.ReplaceItemValue("Reader", "YES");
                            }
                            else
                            {
                                pMailDocument.AppendItemValue("Reader", "YES");
                            }

                            pMailDocument.Save(true, true, true);
                        }
                        else
                        {
                            pMailStruct.Add(DataField.NOTES_UID, DataFormat.STRING, pMailDocument.UniversalID);
                            pMailStruct.Add(DataField.NOTES_UID, DataFormat.STRING, strPUID);
                            pMailStruct.Add(DataField.NOTES_SUBJECT, DataFormat.STRING, strSubject);
                            pMailStruct.Add(DataField.NOTES_FROM, DataFormat.STRING, ((object[])pMailDocument.GetItemValue("Principal"))[0].ToString());
                            pMailStruct.Add(DataField.NOTES_DATE, DataFormat.STRING, ((object[])pMailDocument.ColumnValues)[2].ToString());
                            pMailStruct.Add(DataField.NOTES_SUPERVISORS, DataFormat.STRING, (strSupervisors == "") ? "N/A" : strSupervisors);
                            pMailStruct.Add(DataField.NOTES_CONTENT, DataFormat.STRING, (strBody == "") ? "N/A" : strBody);
                            try
                            {
                                pMailStruct.Add(DataField.NOTES_ATTACHMENTCOUNT, DataFormat.STRING, (((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects == null) ? "0" : ((object[])((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects).Length.ToString());
                            }
                            catch
                            {
                                pMailStruct.Add(DataField.NOTES_ATTACHMENTCOUNT, DataFormat.STRING, "信件内包含多个信件主体,请查阅自己的信箱!");
                            }
                            pMailStruct.AddRows();

                            //GlobalStruct[] pMailStruct = new GlobalStruct[8];

                            //pMailStruct[0].oFieldsName = "Notes_UID";
                            //pMailStruct[0].oFiledsTypes = "String";
                            //pMailStruct[0].oFieldValues = pMailDocument.UniversalID;

                            //pMailStruct[1].oFieldsName = "Notes_PUID";
                            //pMailStruct[1].oFiledsTypes = "String";
                            //pMailStruct[1].oFieldValues = strPUID; // (pMailDocument.ParentDocumentUNID == null) ? "N/A" : pMailDocument.ParentDocumentUNID;

                            //pMailStruct[2].oFieldsName = "Notes_Subject";
                            //pMailStruct[2].oFiledsTypes = "String";
                            //pMailStruct[2].oFieldValues = strSubject;

                            //pMailStruct[3].oFieldsName = "Notes_From";
                            //pMailStruct[3].oFiledsTypes = "String";
                            //pMailStruct[3].oFieldValues = ((object[])pMailDocument.GetItemValue("Principal"))[0].ToString(); //((object[])pMailDocument.ColumnValues)[1].ToString();

                            //pMailStruct[4].oFieldsName = "Notes_Date";
                            //pMailStruct[4].oFiledsTypes = "String";
                            //pMailStruct[4].oFieldValues = ((object[])pMailDocument.ColumnValues)[2].ToString();

                            //pMailStruct[5].oFieldsName = "Notes_Supervisors";
                            //pMailStruct[5].oFiledsTypes = "String";
                            //pMailStruct[5].oFieldValues = (strSupervisors == "") ? "N/A" : strSupervisors;

                            //pMailStruct[6].oFieldsName = "Notes_Content";
                            //pMailStruct[6].oFiledsTypes = "String";
                            //pMailStruct[6].oFieldValues = (strBody == "") ? "N/A" : strBody;

                            //pMailStruct[7].oFieldsName = "Notes_AttachmentCount";
                            //pMailStruct[7].oFiledsTypes = "String";
                            //try
                            //{
                            //    pMailStruct[7].oFieldValues = (((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects == null) ? "0" : ((object[])((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects).Length.ToString();
                            //}
                            //catch
                            //{
                            //    pMailStruct[7].oFieldValues = "信件内包含多个信件主体,请查阅自己的信箱!";
                            //}

                            this.pInfoList.Add(pMailStruct);

                            if (pMailDocument.HasItem("Reader"))
                            {
                                pMailDocument.ReplaceItemValue("Reader", "YES");
                            }
                            else
                            {
                                pMailDocument.AppendItemValue("Reader", "YES");
                            }

                            //pMailStruct = null;

                            pMailDocument.Save(true, true, true);
                            iCount++;
                        }
                    }

                    //pMailDocument.PutInFolder("历史纪录", false);

                    pMailDocument = pMailView.GetNextDocument(pMailDocument);

                    //if (pMailDocument != null)
                    //{
                    //    pMailView.GetPrevDocument(pMailDocument).Remove(false);
                    //}
                }

                this.pRecords = pMailStruct;
                bResult       = true;
            }
            catch (Exception ex)
            {
                this.strMessage = ex.Message;
                Console.WriteLine("丢失Notes个数" + iCount.ToString());
                bResult = false;
                //this.pInfoList.Clear();
            }
            finally
            {
                if (pMailDocument != null)
                {
                    Marshal.ReleaseComObject(pMailDocument);
                }

                if (pMailView != null)
                {
                    Marshal.ReleaseComObject(pMailView);
                }

                pMailDocument = null;
                pMailView     = null;
            }

            return(bResult);
        }
Ejemplo n.º 12
0
        public string Send(MailBody mailBody)
        {
            _MailBody = mailBody;
            InitSettings();
            Validation();
            NotesSession  ns;
            NotesDatabase ndb;

            try
            {
                ns = new NotesSession();
                ns.Initialize(_MailSet.Password);
                //初始化NotesDatabase
                ndb = ns.GetDatabase(_MailSet.SMTPHost, "names.nsf", false);

                NotesDocument doc = ndb.CreateDocument();

                doc.ReplaceItemValue("Form", "Memo");

                //收件人信息
                doc.ReplaceItemValue("SendTo", ConvertToString(_MailBody.MailTo));

                if (_MailBody.MailCc != null && _MailBody.MailCc.Count > 0)
                {
                    doc.ReplaceItemValue("CopyTo", ConvertToString(_MailBody.MailCc));
                }

                if (_MailBody.MailBcc != null && _MailBody.MailBcc.Count > 0)
                {
                    doc.ReplaceItemValue("BlindCopyTo", ConvertToString(_MailBody.MailBcc));
                }

                //邮件主题
                doc.ReplaceItemValue("Subject", _MailBody.Subject);

                //邮件正文
                if (_MailBody.IsHtmlBody)
                {
                    NotesStream body = ns.CreateStream();
                    body.WriteText(_MailBody.Body, EOL_TYPE.EOL_PLATFORM);
                    NotesMIMEEntity mime = doc.CreateMIMEEntity("Body");
                    mime.SetContentFromText(body, "text/HTML;charset=gb2312", MIME_ENCODING.ENC_NONE);
                    body.Truncate();
                }
                else
                {
                    NotesRichTextItem rt = doc.CreateRichTextItem("Body");
                    rt.AppendText(_MailBody.Body);
                }

                //发送邮件
                object obj = doc.GetItemValue("SendTo");
                doc.Send(false, ref obj);
                doc = null;
                return("");
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                return("发送邮件失败");
            }
            finally
            {
                ndb = null;
                ns  = null;
            }
        }