/// <summary>
        /// Sends the via notes.
        /// </summary>
        /// <param name="settings">Any settings needed</param>
        /// <param name="month">The month.</param>
        /// <param name="year">The year.</param>
        /// <param name="fullFilename">The full filename.</param>
        /// <param name="emailAddress">The email address.</param>
        /// <param name="password">The password required to submit</param>
        public void Send(Settings settings, string month, string year, string fullFilename, string emailAddress, SecureString password = null)
        {
            // Two digit month and four digit year
            NotesSession session = new NotesSession();

            session.Initialize();
            NotesDatabase database = session.GetDatabase("Pride/Tessella", "mail\\waldm.nsf");

            if (!database.IsOpen)
            {
                database.Open();
            }

            NotesDocument document = database.CreateDocument();

            document.ReplaceItemValue("Form", "Memo");
            document.ReplaceItemValue("Sendto", emailAddress);
            string subject = settings.StaffID + " " + month + "/" + year;

            document.ReplaceItemValue("Subject", subject);

            NotesRichTextItem attachment = document.CreateRichTextItem("Attachment");

            attachment.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, string.Empty, fullFilename, "Attachment");

            document.SaveMessageOnSend = true;
            document.ReplaceItemValue("PostedDate", DateTime.Now);
            document.Send(false, emailAddress);
        }
Exemple #2
0
        private static void SendUsingLotusNotes(string[] mailingList, IMessage message)
        {
            string serverName = WebConfigurationManager.AppSettings["LotusNotesServerName"];
            string mailFile   = WebConfigurationManager.AppSettings["LotusNotesMailFileName"];
            string password   = WebConfigurationManager.AppSettings["LotusNotesPassword"];

            string[] sendTo      = mailingList;
            string[] copyTo      = { };
            string   replyTo     = message.ReplyTo;
            string   blindCopyTo = "";
            string   subject     = message.Subject;

            //Create new notes session
            NotesSession notesSession = new NotesSession();

            notesSession.Initialize(password);

            //Get and open NotesDataBase
            NotesDatabase notesDataBase = notesSession.GetDatabase(serverName, mailFile, false);

            if (!notesDataBase.IsOpen)
            {
                notesDataBase.Open();
            }

            //Create the notes document
            NotesDocument notesDocument = notesDataBase.CreateDocument();

            //Set document type
            notesDocument.ReplaceItemValue("Form", "Memo");

            //Set notes memo fields (To: CC: Bcc: Subject etc)
            notesDocument.ReplaceItemValue("SendTo", sendTo);
            notesDocument.ReplaceItemValue("CopyTo", copyTo);
            notesDocument.ReplaceItemValue("BlindCopyTo", blindCopyTo);
            notesDocument.ReplaceItemValue("ReplyTo", replyTo);
            notesDocument.ReplaceItemValue("Subject", subject);

            //Set notes Body as HTML
            NotesStream notesStream = notesSession.CreateStream();

            notesStream.WriteText(message.Body);
            notesStream.WriteText("");
            notesStream.WriteText(message.Link);

            NotesMIMEEntity mimeItem = notesDocument.CreateMIMEEntity("Body");

            mimeItem.SetContentFromText(notesStream, "text/html; charset=UTF-8", MIME_ENCODING.ENC_NONE);

            notesDocument.Send(false);
        }
 public void Open() => database.Open();
        public void ExtractGraphicsCafeDocuments()
        {
            var specificCategories = ReadSpecificCategories();

            Console.WriteLine("Initialize the Extract with Cred: Server: " + LotusNotesServer + " Password: "******"Reading file: " + db.FileName);
                    if (db != null && db.FileName.ToLower() == "Graphics Cafe.nsf".ToLower())
                    {
                        Console.WriteLine("Reading file: " + db.FileName);
                        isAlive = false;
                        try
                        {
                            if (!db.IsOpen)
                            {
                                db.Open();
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Unable to open database: " + db.FileName);
                            Console.WriteLine("Exception: " + ex);
                            db = d.GetNextDatabase();
                            continue;
                        }
                        NotesDocumentCollection docs = db.AllDocuments;

                        if (docs != null)
                        {
                            Console.WriteLine("Documents Count: " + db.AllDocuments.Count);
                            string rootFolderName    = Path.GetFileNameWithoutExtension(db.FileName);
                            string baseDirectoryPath = BaseDirectoryPath + rootFolderName + "\\";

                            for (int rowCount = 1; rowCount <= docs.Count; rowCount++)
                            {
                                NotesDocument document = docs.GetNthDocument(rowCount);
                                if (document.HasEmbedded && document.HasItem("$File"))
                                {
                                    object[]      AllDocItems   = (object[])document.Items;
                                    string        category      = string.Empty;
                                    List <string> categories    = new List <string>();
                                    string        subCategory   = string.Empty;
                                    List <string> subCategories = new List <string>();
                                    Console.WriteLine("RowIndex: " + rowCount);
                                    string documentDescription = string.Empty;
                                    string documentDate        = string.Empty;
                                    string documentNotes       = string.Empty;
                                    string documentAuthor      = string.Empty;
                                    var    notesItems          = new List <NotesItem>();
                                    foreach (object CurItem in AllDocItems)
                                    {
                                        notesItems.Add((NotesItem)CurItem);
                                    }

                                    var categoryItem = notesItems.FirstOrDefault(x => x.Name == "Category");
                                    if (categoryItem != null && !string.IsNullOrEmpty(categoryItem.Text))
                                    {
                                        category = categoryItem.Text;
                                    }
                                    var subcategoryItem = notesItems.FirstOrDefault(x => x.Name == "SubCategory");

                                    if (subcategoryItem != null && !string.IsNullOrEmpty(subcategoryItem.Text))
                                    {
                                        subCategory = subcategoryItem.Text;
                                    }

                                    var descriptionItem = notesItems.FirstOrDefault(x => x.Name == "Description");
                                    if (descriptionItem != null && !string.IsNullOrEmpty(descriptionItem.Text))
                                    {
                                        documentDescription = descriptionItem.Text;
                                    }

                                    var notesItem = notesItems.FirstOrDefault(x => x.Name == "Notes");
                                    if (notesItem != null && !string.IsNullOrEmpty(notesItem.Text))
                                    {
                                        documentNotes = notesItem.Text;
                                    }

                                    var dateItem = notesItems.FirstOrDefault(x => x.Name == "tmpDate");
                                    if (dateItem != null && !string.IsNullOrEmpty(dateItem.Text))
                                    {
                                        documentDate = dateItem.Text;
                                    }

                                    var authorItem = notesItems.FirstOrDefault(x => x.Name == "tmpAuthor");
                                    if (authorItem != null && !string.IsNullOrEmpty(authorItem.Text))
                                    {
                                        documentAuthor = authorItem.Text;
                                    }

                                    if (!string.IsNullOrEmpty(category))
                                    {
                                        categories = category.Split(';').ToList();
                                    }
                                    if (!string.IsNullOrEmpty(subCategory))
                                    {
                                        subCategories = subCategory.Split(';').ToList();
                                    }

                                    if (specificCategories.Count == 0 || (specificCategories.Count > 0 && (categories.Any(x => specificCategories.Contains(x)) || subCategories.Any(x => specificCategories.Contains(x)))))
                                    {
                                        List <NotesItem> documentItems = notesItems.Where(x => x.type == IT_TYPE.ATTACHMENT).ToList();
                                        if (documentItems != null && documentItems.Count > 0)
                                        {
                                            foreach (var nItem in documentItems)
                                            {
                                                if (IT_TYPE.ATTACHMENT == nItem.type)
                                                {
                                                    var pAttachment = ((object[])nItem.Values)[0].ToString();
                                                    Console.WriteLine("Description: " + documentDescription);
                                                    Console.WriteLine("Date: " + documentDate);
                                                    Console.WriteLine("Notes: " + documentNotes);
                                                    Console.WriteLine("Author: " + documentAuthor);
                                                    foreach (var cat in categories)
                                                    {
                                                        Console.WriteLine("Category: " + cat);
                                                        string destPath = baseDirectoryPath;
                                                        if (!string.IsNullOrEmpty(cat))
                                                        {
                                                            if (!Directory.Exists(baseDirectoryPath + cat))
                                                            {
                                                                Directory.CreateDirectory(baseDirectoryPath + cat);
                                                            }
                                                            destPath = destPath + cat + "\\";
                                                        }

                                                        foreach (var subcat in subCategories)
                                                        {
                                                            Console.WriteLine("SubCategory: " + subcat);

                                                            if (!string.IsNullOrEmpty(subcat))
                                                            {
                                                                if (!Directory.Exists(baseDirectoryPath + cat + "\\" + subcat))
                                                                {
                                                                    Directory.CreateDirectory(baseDirectoryPath + cat + "\\" + subcat);
                                                                }
                                                                destPath = destPath + subcat + "\\";
                                                            }
                                                        }
                                                        Console.WriteLine("Final Destination Path: " + destPath + pAttachment);
                                                        if (!File.Exists(destPath + pAttachment))
                                                        {
                                                            try
                                                            {
                                                                document.GetAttachment(pAttachment).ExtractFile(destPath + pAttachment);
                                                            }
                                                            catch (Exception exe)
                                                            {
                                                                LogDetails("File not extracted: " + destPath + pAttachment);
                                                                LogExceptionDetails("File not extracted: " + destPath + pAttachment, exe);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            Console.WriteLine("File already exists: " + destPath + pAttachment);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (isAlive)
                    {
                        db = d.GetNextDatabase();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Extract Graphics Cafe Documents Exception:" + ex);
            }
        }