public MailAttachmentTransform(int recurseDepth, MsOutlook._Application olApplication, bool disableAccessToDOMAttachments = false)
		{
			if (recurseDepth > AbsoluteMailNestingDepth || recurseDepth < 0)
				throw new ArgumentException(string.Format(System.Globalization.CultureInfo.InvariantCulture,
					"Only supports a nesting level between 0 and {0}", AbsoluteMailNestingDepth), "recurseDepth");
			m_application = olApplication;
			m_nestingLimit = recurseDepth;
			if (m_application == null)
			{
				try
				{
					m_application = new WsApplication(new MsOutlook.Application(), false);
				}
				catch (COMException)
				{
					Thread.Sleep(1000);
                    m_application = new WsApplication(new MsOutlook.Application(), false);
				}
			}

            if (disableAccessToDOMAttachments)
            {
				m_mat = Oif.CreateWSMailAttachmentTransform();
            }
			else
            {				
				m_mat = Oif.CreateOOMWSMailAttachmentTransform();
            }
			m_mat.OutlookApp = m_application;
		}
        /// <summary>
        /// Constructor
        /// </summary>
        public MailConnection()
        {
            // Checks whether an Outlook process is currently running
            try
            {
                if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
                {
                    Log.Out(Log.Severity.Info, "Connection", "Connecting to an existing Outlook instance");
                    _outlook = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
                    _keepOutlookRunning = true;
                    return;
                }

                // Creates a new instance of Outlook and logs on to the specified profile.
                Log.Out(Log.Severity.Info, "Connection", "Starting a new Outlook session");

                _outlook = new Outlook.Application();
                Outlook.NameSpace nameSpace = _outlook.GetNamespace("MAPI");
                Outlook.Folder mailFolder = (Outlook.Folder)nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            }
            catch (Exception)
            {
                Log.Out(Log.Severity.Error, "Connection", "Error encountered when connecting to Outlook ");
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// <c>ReConnection</c> member function
        /// this function recreates the deleted  folder in outlook 
        /// </summary>
        /// <param name="xLogProperties"></param>
        /// <param name="parentfolder"></param>
        /// <returns></returns>
        public bool ReConnection(XMLLogProperties xLogProperties, Outlook.MAPIFolder parentfolder)
        {
            bool result = false;
            try
            {

                Outlook.MAPIFolder newFolder = null;
                ////////////////////////updated by Joy on 25.07.2012/////////////////
                Outlook.MAPIFolder newBrokenUploadsFolder = null;
                ////////////////////////updated by Joy on 25.07.2012/////////////////
                //outlookObj = new Outlook.Application();
                OutlookObj = Globals.ThisAddIn.Application;

                //Gte MAPI Name space
                outlookNameSpace = OutlookObj.GetNamespace("MAPI");
                Outlook.MAPIFolder olInboxFolder = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

                Outlook.MAPIFolder Target = parentfolder;

                bool created = CreateFolderInOutLookSideMenu(xLogProperties.DisplayFolderName, xLogProperties.SiteURL, out newFolder, Target);

                if (created == true && newFolder != null)
                {

                    //Set new folder location
                    xLogProperties.OutlookFolderLocation = newFolder.FolderPath;
                    //Create node in xml file
                    //  UserLogManagerUtility.CreateXMLFileForStoringUserCredentials(xLogProperties);

                    MAPIFolderWrapper omapi = null;
                    if (string.IsNullOrEmpty(xLogProperties.DocumentLibraryName) == true)
                    {
                        //Doc name is empty means Folder is not mapped with Doc Lib
                        omapi = new MAPIFolderWrapper(ref  newFolder, addinExplorer, false);
                    }
                    else
                    {
                        omapi = new MAPIFolderWrapper(ref newFolder, addinExplorer, true);
                    }

                    newFolders.Add(omapi);

                }

            }
            catch (Exception ex)
            {

            }
            return result;
        }
Exemple #4
0
        /// <summary>
        ///<c>ThisAddIn_Startup</c>  Outlook startup event
        /// This Event is  executed when outlook starts(outlook is opened)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            try
            {

                //declare and initialize variables used for the Instant PLUS check
                Int32 result = 0;

                string filePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\ITOPIA\\SharePoint Link 2010\\", "SharePoint Link.xml");

                //Make the call to Instant PLUS and store the result
                result = Ip2LibManaged.CallInstantPLUS(Ip2LibManaged.FLAGS_NONE, "30820274020100300D06092A864886F70D01010105000482025E3082025A02010002818100BA81817A32C249909671428137ECFC2AEF45E5F746C218550C2191F525A15E65DCD87CAD8B46EB870E55897D1D185B9D88BCDDB6D44CB8B9DDFD7DB4948E8CF91743377F31DB733438828CA0EC3176D8650C8F4B77578E60285F55049D9A707C61FF75C7C626492415BBCBE8058E4F220826A356F1C50B29C92B354C61BEF21F0201110281800AF88F254E47A9F97242E5CB5DA4874DD1D6EF68E60B6AD7D389810E6BA0149C94853482ADD6FECBB58C8F9DF2A71472ADB0C1BF75E665381C1DF855EA9EF93BBA5432731B506EDFE944C217EB09F27AA8203C7D7310D78995A9549690836B313CDCD0B2FA6AD79576977EB44B33D46577E9EA6939DCF8388761E25C3FADF9B1024100F3F70346EEA01874427576DFF5136A9B3A1AB4522ADD2073669376540C6CE65A1A613D0F4754FAD4C8DA70D3F5F5F0D4DAF97B0CF49D9BDA0ECE0F8F46A19BBF024100C3B4DA9372E3FDE1787C322A5B74F21800CDD6A4A85C1DC9D18D40B0F8736BDD3CF45CD5DDB8FD626CD1F11B1127439036A4974D257AF38EBCDD1D9CE08FC1A1024100AC35E43211DA6B9D5C16AE43BC0DB4A9CEA9703A00239E6F93B36295AE6AFCF44EDB3A28E70ECF2CCA039AEFF8E9D72CD6CE38BDD9D8AA3F91FADDCE8C35D75902405095C369E40386A8228D7E1170F3EB370F63D0DA63713971382B1AA3392077B57373ADC1796A4A3796385438525B762C52BC3E4CF150BEA42FA6577CD4EFE65102405162E2024CE04279E92731B490BE2431758FA6D032B0DB85B2AC782956832095800B4A8AB7D6FC1DB905CA38508FC3CC49994A48940CF9BB5761C07A9289D492", filePath);

                if (11574 != result)
                {
                    //this.Close();
                    //this.Application.ActiveExplorer().Close();
                    //this.Application.Quit();
                    return;
                }

                isAuthorized = true;

                #region Add-in Express Regions generated code - do not modify
                this.FormsManager = AddinExpress.OL.ADXOlFormsManager.CurrentInstance;
                this.FormsManager.OnInitialize +=
                    new AddinExpress.OL.ADXOlFormsManager.OnComponentInitialize_EventHandler(this.FormsManager_OnInitialize);
                //this.FormsManager.ADXBeforeFolderSwitchEx +=
                //     new AddinExpress.OL.ADXOlFormsManager.BeforeFolderSwitchEx_EventHandler(FormsManager_ADXBeforeFolderSwitchEx);

                this.FormsManager.Initialize(this);
                #endregion

                //DateTime dtExpiredDate = new DateTime(2010, 08, 05);
                //DateTime dtWorkingDate = DateTime.Now;
                //TimeSpan t = new TimeSpan();
                //t = dtExpiredDate.Subtract(dtWorkingDate);

                //if (t.Days < 30 && t.Days >= 0)
                //{

                //outlookObj = new Outlook.Application();

                OutlookObj = Globals.ThisAddIn.Application;
                //Gte MAPI Name space
                outlookNameSpace = OutlookObj.GetNamespace("MAPI");

                //Get inbox folder
                Outlook.MAPIFolder oInBox = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                //Get current user details to save the xml file based on user
                string userName = outlookNameSpace.DefaultStore.DisplayName;
                userName = userName.Replace("-", "_");
                userName = userName.Replace(" ", "");
                UserLogManagerUtility.UserXMLFileName = userName;

                //Get parent root folder
                Outlook.MAPIFolder olMailRootFolder = (Outlook.MAPIFolder)oInBox.Parent;
                //Get all folder
                oMailRootFolders = olMailRootFolder.Folders;
                //Create folder remove event
                oMailRootFolders.FolderRemove += new Microsoft.Office.Interop.Outlook.FoldersEvents_FolderRemoveEventHandler(oMailRootFolders_FolderRemove);

                //Set inbox folder as default

                try
                {

                    OutlookObj.ActiveExplorer().CurrentFolder = oInBox;
                    addinExplorer = this.Application.ActiveExplorer();
                    addinExplorer.BeforeItemPaste += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_BeforeItemPasteEventHandler(addinExplorer_BeforeItemPaste);
                    //Create folder Switch event
                    addinExplorer.FolderSwitch += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_FolderSwitchEventHandler(addinExplorer_FolderSwitch);

                    //crete folder context menu disply
                    this.Application.FolderContextMenuDisplay += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_FolderContextMenuDisplayEventHandler(Application_FolderContextMenuDisplay);

                    this.Application.ContextMenuClose += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ContextMenuCloseEventHandler(Application_ContextMenuClose);

                    strParentMenuTag = strParentMenuName;
                    // Removing the Existing Menu Bar
                    //  RemoveItopiaMenuBarIfExists(strParentMenuTag);
                    // Adding The Menu Bar Freshly
                    //  CreateParentMenu(strParentMenuTag, strParentMenuName);
                    myTargetFolder = oInBox;
                    CreateAddEventOnFolders();
                    //CreateDefaultAddEventOnFolders();
                    //Create outlook explorer wrapper class
                    OutlookWindow = new OutlookExplorerWrapper(OutlookObj.ActiveExplorer());
                    OutlookWindow.Close += new EventHandler(OutlookWindow_Close);

                    ((Outlook.ExplorerEvents_Event)addinExplorer).BeforeFolderSwitch += new Microsoft.Office.Interop.Outlook.ExplorerEvents_BeforeFolderSwitchEventHandler(ThisAddIn_BeforeFolderSwitch);

                    oMailRootFolders.FolderChange += new Outlook.FoldersEvents_FolderChangeEventHandler(oMailRootFolders_FolderChange);

                    foreach (Outlook.MAPIFolder item in oMailRootFolders)
                    {

                        try
                        {
                            item.Folders.FolderChange -= new Outlook.FoldersEvents_FolderChangeEventHandler(oMailRootFolders_FolderChange);

                        }
                        catch (Exception)
                        {
                        }
                        item.Folders.FolderChange += new Outlook.FoldersEvents_FolderChangeEventHandler(oMailRootFolders_FolderChange);

                    }

                    Outlook.Items activeDroppingFolderItems;

                    activeDroppingFolderItems = oInBox.Items;

                    userOptions = UserLogManagerUtility.GetUserConfigurationOptions();
                    currentFolderSelected = oInBox.Name;
                    currentFolderSelectedGuid = oInBox.EntryID;
                }
                catch (Exception ex)
                {
                    ListWebClass.Log(ex.Message, true);
                }

                // }

            }
            catch (Exception ex)
            {
                EncodingAndDecoding.ShowMessageBox("StartUP", ex.Message, MessageBoxIcon.Error);
            }

            /// <summary>
            //code written by Joy
            ///initializes the object of timer
            /// </summary>

            System.Threading.AutoResetEvent reset = new System.Threading.AutoResetEvent(true);

            timer = new System.Threading.Timer(new System.Threading.TimerCallback(doBackgroundUploading), reset, 180000, 180000);

            GC.KeepAlive(timer);
            form = new Form();
            form.Opacity = 0.01;
            form.Show();
            form.Visible = false;
        }
Exemple #5
0
        /// <summary>
        /// code written by Joy
        /// moves or copies mail items to the selected mapped folder
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren() == true)
            {
                if (ThisAddIn.IsUploadingFormIsOpen == true)
                {
                    if (Globals.ThisAddIn.frmlistObject != null)
                    {
                        Globals.ThisAddIn.frmlistObject.progressBar1.Value = Globals.ThisAddIn.frmlistObject.progressBar1.Minimum;
                        Globals.ThisAddIn.frmlistObject.lblPRStatus.Text = "";
                    }

                }
                string selected_mapiFolderName = cmbOptions.Text;
                this.Close();
                if (Globals.ThisAddIn.copy_button_clicked == true)
                {
                    OutlookObj = Globals.ThisAddIn.Application;
                    outlookNameSpace = OutlookObj.GetNamespace("MAPI");
                    olInBox = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                    parentFolder = (Microsoft.Office.Interop.Outlook.MAPIFolder)olInBox.Parent;
                    string mappedFolderName = cmbOptions.SelectedItem.ToString();
                    mappedFolder = MAPIFolderWrapper.GetFolder(parentFolder, mappedFolderName);
                    Outlook.MailItem mItem;
                    Outlook.MailItem copyMail;
                    Globals.ThisAddIn.isCopyRunninng = true;
                    foreach (Object obj in Globals.ThisAddIn.copySelected)
                    {
                        if (obj is Outlook.MailItem)
                        {
                            mItem = (Outlook.MailItem)obj;
                            copyMail = mItem.Copy() as Outlook.MailItem;
                            copyMail.Move(mappedFolder);
                            //doBackGroundUpload(mItem);
                        }
                    }
                }
                else if (Globals.ThisAddIn.move_button_clicked == true)
                {

                        OutlookObj = Globals.ThisAddIn.Application;
                        outlookNameSpace = OutlookObj.GetNamespace("MAPI");
                        olInBox = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                        parentFolder = (Microsoft.Office.Interop.Outlook.MAPIFolder)olInBox.Parent;
                        string mappedFolderName = cmbOptions.SelectedItem.ToString();
                        mappedFolder = MAPIFolderWrapper.GetFolder(parentFolder, mappedFolderName);
                        Outlook.MailItem mItem;
                        Globals.ThisAddIn.isMoveRunning = true;
                        foreach (Object obj in Globals.ThisAddIn.moveSelected)
                        {
                            if (obj is Outlook.MailItem)
                            {
                                mItem = (Outlook.MailItem)obj;
                                mItem.Move(mappedFolder);
                                //doBackGroundUpload(mItem);
                            }
                        }

                }
            }
            else
                return;
        }
Exemple #6
0
 static Outlook.MailItem ReadMsgFile(Outlook._Application app, string path) => app.Session.OpenSharedItem(path);
Exemple #7
0
        /*
         * Does sanity checks, opens outlook, create pdf, sends email.
         */
        private void SendButton_Click(object sender, EventArgs e)
        {
            // for the if statement to check if jobNumberTextBox contains "\" there has to be two \ 
            // since it is an escape character meaning remove special meaning in code.
            // Thus you have to us \ to remove the special meaning behind \ or use \ to remove special
            // meaning behind ".

            // If statement checks to see if job number contains anything that windows file system
            // does not allow since it is used to create the pdf name.
            if (jobNumberTextBox.Text.Contains("~") ||
                jobNumberTextBox.Text.Contains("\"") ||
                jobNumberTextBox.Text.Contains("#") ||
                jobNumberTextBox.Text.Contains("%") ||
                jobNumberTextBox.Text.Contains("&") ||
                jobNumberTextBox.Text.Contains("*") ||
                jobNumberTextBox.Text.Contains(":") ||
                jobNumberTextBox.Text.Contains(">") ||
                jobNumberTextBox.Text.Contains("<") ||
                jobNumberTextBox.Text.Contains("?") ||
                jobNumberTextBox.Text.Contains("/") ||
                jobNumberTextBox.Text.Contains("\\") ||
                jobNumberTextBox.Text.Contains("{") ||
                jobNumberTextBox.Text.Contains("|") ||
                jobNumberTextBox.Text.Contains("}"))
            {
                MessageBox.Show(jobNumberLabel.Text.ToString() + " cannot contain ~ \" # % & * : < > ? / \\ { | }");
            }
            // All these else if's make sure that data has been entered
            else if (jobNumberTextBox.Text.ToString() == "")
            {
                MessageBox.Show(jobNumberLabel.Text.ToString() + " cannot be blank");
            }
            else if (foremanOnSiteTextBox.Text.ToString() == "")
            {
                MessageBox.Show(foremanOnSiteLabel.Text.ToString() + " cannot be blank");
            }
            else if (siteForemanAssistantTextBox.Text.ToString() == "")
            {
                MessageBox.Show(siteForemanAssistentLabel.Text.ToString() + " cannot be blank");
            }
            else if (projectNameTextBox.Text.ToString() == "")
            {
                MessageBox.Show(projectNameLabel.Text.ToString() + " cannot be blank");
            }
            else if (manPowerAssessmentTextBox.Text.ToString() == "")
            {
                MessageBox.Show(manPowerAssessmentLabel.Text.ToString() + " cannot be blank");
            }
            else if (safetyConcernsTextBox.Text.ToString() == "")
            {
                MessageBox.Show(safetyConcernsLabel.Text.ToString() + " cannot be blank");
            }
            else if (ahaReviewedTextBox.Text.ToString() == "")
            {
                MessageBox.Show(ahaReviewedLabel.Text.ToString() + " cannot be blank");
            }
            else if (scheduleConcernsTextBox.Text.ToString() == "")
            {
                MessageBox.Show(scheduleConcernsLabel.Text.ToString() + " cannot be blank");
            }
            else if (budgetConcernsTextBox.Text.ToString() == "")
            {
                MessageBox.Show(budgetConcernsLabel.Text.ToString() + " cannot be blank");
            }
            else if (deliveriesReceivedTextBox.Text.ToString() == "")
            {
                MessageBox.Show(deliveriesReceivedLabel.Text.ToString() + " cannot be blank");
            }
            else if (deliveriesNeededTextBox.Text.ToString() == "")
            {
                MessageBox.Show(deliveriesNeededLabel.Text.ToString() + " cannot be blank");
            }
            else if (newWorkAuthorizationsTextBox.Text.ToString() == "")
            {
                MessageBox.Show(newWorkAuthorizationsLabel.Text.ToString() + " cannot be blank");
            }
            else if (qcInspectionTextBox.Text.ToString() == "")
            {
                MessageBox.Show(qcInspectionLabel.Text.ToString() + " cannot be blank");
            }
            else if (notesCorrespondenceTextBox.Text.ToString() == "")
            {
                MessageBox.Show(notesCorrespondenceLabel.Text.ToString() + " cannot be blank");
            }
            else if (actionItemsTextBox.Text.ToString() == "")
            {
                MessageBox.Show(actionItemsLabel.Text.ToString() + " cannot be blank");
            }
            else if (commentsAboutShopTextBox.Text.ToString() == "")
            {
                MessageBox.Show(commentsAboutShopLabel.Text.ToString() + " cannot be blank");
            }
            else if (toTextBox.Text.ToString() == "")
            {
                MessageBox.Show(toLabel.Text.ToString() + " cannot be blank");
            }
            else if (toTextBox.Text.ToString().Contains("/n"))
            {
                MessageBox.Show(toLabel.Text.ToString() + " cannot have 'enters' or page breaks");
            }
            else
            {
                // try block catches and boiles up the errors that are found. Especially since this is
                // an error prone area.
                try
                {
                    string fileLocation;
                    string fileName;


                    // Convert current date and time to string (words)
                    String   sDate     = DateTime.Now.ToString();
                    DateTime datevalue = (Convert.ToDateTime(sDate.ToString()));

                    // Extract day, month, and year to be used in the email and pdf name.
                    String dy = datevalue.Day.ToString();
                    String mn = datevalue.Month.ToString();
                    String yy = datevalue.Year.ToString();

                    String date = yy + "-" + mn + "-" + dy;

                    // Compile the beginning part of the Daily Log as html for email.
                    // Used *Label.Text to make the email reflect the daily log labels text for
                    // both consistency, and easier editing.
                    string body = "<html><body><b>" + jobNumberLabel.Text + "</b> " + jobNumberTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                                  + "<b>" + foremanOnSiteLabel.Text + "</b> " + foremanOnSiteTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                                  + "<b>" + siteForemanAssistentLabel.Text + "</b> " + siteForemanAssistantTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                                  + "<b>" + projectNameLabel.Text + "</b> " + projectNameTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                                  + "<b>" + "Date:" + "</b> " + DateTime.Now + "<br><br>"
                                  + "<b>" + "To:" + "</b> " + toTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                                  // Start on table in html for email
                                  + "<table class=fixed border=1 style=width:100% cellpadding='1'>"
                                  + "<caption>" + manpowerLabel.Text.ToString() + "</caption>";
                    // loop through Daily Log table to construct html table
                    // this for loop goes through the rows
                    for (int row = 0; row < manpower.RowCount; row++)
                    {
                        // Bad sloppy code that does not account for number of column headers. Works though...
                        if (row == 0)
                        {
                            body += "<tr><th><b>" + manpower.Columns[0].HeaderText.ToString() + "</b></th>";
                            body += "<th><b>" + manpower.Columns[1].HeaderText.ToString() + "</b></th>";
                            body += "<th><b>" + manpower.Columns[2].HeaderText.ToString() + "</b></th></tr>";
                        }
                        body += "<tr>";
                        // this for loop goes through the columns
                        for (int column = 0; column < manpower.ColumnCount; column++)
                        {
                            body += "<td>";
                            body += manpower.Rows[row].Cells[column].Value;
                            body += "</td>";
                        }
                        body += "</tr>";
                    }
                    body += "</table><br>"
                            // Start on table in html for email
                            + "<table class=fixed border=1 style=width:100% cellpadding='1'>"
                            + "<caption>" + weeklyScheduleLabel.Text.ToString() + "</caption>";
                    // this for loop goes through the rows
                    for (int row = 0; row < weeklySchedule.RowCount; row++)
                    {
                        // Bad sloppy code that does not account for number of column headers. Works though...
                        if (row == 0)
                        {
                            body += "<tr><th><b>" + weeklySchedule.Columns[0].HeaderText.ToString() + "</b></th>";
                            body += "<th><b>" + weeklySchedule.Columns[1].HeaderText.ToString() + "</b></th>";
                            body += "<th><b>" + weeklySchedule.Columns[2].HeaderText.ToString() + "</b></th>";
                            body += "<th><b>" + weeklySchedule.Columns[3].HeaderText.ToString() + "</b></th>";
                            body += "<th><b>" + weeklySchedule.Columns[4].HeaderText.ToString() + "</b></th>";
                            body += "<th><b>" + weeklySchedule.Columns[5].HeaderText.ToString() + "</b></th></tr>";
                        }
                        body += "<tr>";
                        // this for loop goes through the columns
                        for (int column = 0; column < weeklySchedule.ColumnCount; column++)
                        {
                            body += "<td>";
                            if (column == 0)
                            {
                                body += "<b>" + weeklySchedule.Rows[row].Cells[column].Value + "</b>";
                            }
                            else
                            {
                                body += weeklySchedule.Rows[row].Cells[column].Value;
                            }
                            body += "</td>";
                        }
                        body += "</tr>";
                    }
                    body += "</table>"
                            // Compiles all the ending information into html for table use
                            + "<br>"
                            + "<b>" + manPowerAssessmentLabel.Text + "</b><br>" + manPowerAssessmentTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                            + "<b>" + safetyConcernsLabel.Text + "</b><br>" + safetyConcernsTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                            + "<b>" + ahaReviewedLabel.Text + "</b><br>" + ahaReviewedTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                            + "<b>" + safetyConcernsLabel.Text + "</b><br>" + scheduleConcernsTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                            + "<b>" + budgetConcernsLabel.Text + "</b><br>" + budgetConcernsTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                            + "<b>" + deliveriesReceivedLabel.Text + "</b><br>" + deliveriesReceivedTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                            + "<b>" + deliveriesNeededLabel.Text + "</b><br>" + deliveriesNeededTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                            + "<b>" + newWorkAuthorizationsLabel.Text + "</b><br>" + newWorkAuthorizationsTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                            + "<b>" + qcInspectionLabel.Text + "</b><br>" + qcInspectionTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                            + "<b>" + notesCorrespondenceLabel.Text + "</b><br>" + notesCorrespondenceTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                            + "<b>" + actionItemsLabel.Text + "</b><br>" + actionItemsTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                            + "<b>" + commentsAboutShopLabel.Text + "</b><br>" + commentsAboutShopTextBox.Text.Replace("\n", "<br>") + "<br><br>"
                            + "</body></html>";

                    // Creates outlook application by calling constructor
                    Outlook._Application app = CreateOutlookApp();

                    // Creates new email from the application
                    Outlook.MailItem mail = app.CreateItem(Outlook.OlItemType.olMailItem);

                    // Adds the "To" box into the email
                    mail.To = toTextBox.Text.ToString();

                    // Adds the cc text into the email
                    mail.CC = ccLabelBox.Text;

                    // Compiles the subject
                    mail.Subject = "Foreman Daily Log " + jobNumberTextBox.Text.ToString() + "_" + date;

                    // Adds the html made in above code before the creation of an outlook app
                    mail.HTMLBody = body;

                    // Sets the importance to normal
                    mail.Importance = Outlook.OlImportance.olImportanceNormal;

                    // Determines the name of the folder to store all the pdf's
                    fileLocation = "Saved Foreman Daily Logs";

                    // Creates the name for the pdf's
                    fileName = jobNumberTextBox.Text.ToString() + "_" + date + ".pdf";

                    // This line of code reads best right to left. It creates the pdf getting
                    // the html info, the object location, and then the name of the object.
                    // Then attaches the newly made file as a pdf.
                    mail.Attachments.Add(CreatePDF(body, fileLocation, fileName));

                    // Sends the email
                    ((Outlook._MailItem)mail).Send();

                    // Display a sent message
                    MessageBox.Show("Your message has been successfully sent!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex)
                {
                    // Catch if error is outlook does not recognize all emails
                    if (ex.GetHashCode() == 44307222)
                    {
                        MessageBox.Show("Outlook does not recognize all the emails entered in the 'To' box. Make sure that they are all correct, and that there is a ';' in between each email.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    // If other error messages then show them
                    else
                    {
                        MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
		protected virtual void Dispose(bool disposing)
		{
            if (m_application != null)
            {
                ((WsApplication)m_application).Dispose();
                m_application = null;
            }

			if (m_mat != null)
			{
				m_mat.Dispose();
				m_mat = null;
			}

		}
        /// <summary>
        /// code written by Joy
        /// excutes ansd the start the timer upload process when the backgoundworkers's do work event fires
        /// </summary>
        /// <param name="Item"></param>
        void doBackGroundUpload(object Item)
        {
            try
              {

              Globals.ThisAddIn.isTimerUploadRunning = true;
              OutlookObj = Globals.ThisAddIn.Application;
              outlookNameSpace = OutlookObj.GetNamespace("MAPI");
              Outlook.MAPIFolder oInBox = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
              Outlook.MAPIFolder olMailRootFolder = (Outlook.MAPIFolder)oInBox.Parent;
              oMailRootFolders = olMailRootFolder.Folders;
              Outlook.MailItem moveMail = (Outlook.MailItem)Item;
              string newCatName = "Successfully Uploaded";
              if (Globals.ThisAddIn.Application.Session.Categories[newCatName] == null)
              {
                  outlookNameSpace.Categories.Add(newCatName, Outlook.OlCategoryColor.olCategoryColorDarkGreen, Outlook.OlCategoryShortcutKey.olCategoryShortcutKeyNone);
              }

              XmlNode uploadFolderNode = UserLogManagerUtility.GetSPSiteURLDetails("", folderName);

              if (uploadFolderNode != null)
              {
                  bool isDroppedItemUplaoded = false;

                  addinExplorer = ThisAddIn.OutlookObj.ActiveExplorer();

                  //Check the folder mapping with documnet library

                  if (isUserDroppedItemsCanUpload == false)
                  {
                      //Show message
                      try
                      {

                          Outlook.MailItem m = (Outlook.MailItem)Item;
                          mailitemEntryID = m.EntryID;

                          try
                          {
                              mailitem = m;

                              mailitemEntryID = m.EntryID;

                              string strsubject = m.EntryID;
                              if (string.IsNullOrEmpty(strsubject))
                              {
                                  strsubject = "tempomailcopy";
                              }

                              mailitemEntryID = strsubject;

                              string tempFilePath = UserLogManagerUtility.RootDirectory + "\\" + strsubject + ".msg";

                              if (Directory.Exists(UserLogManagerUtility.RootDirectory) == false)
                              {
                                  Directory.CreateDirectory(UserLogManagerUtility.RootDirectory);
                              }
                              m.SaveAs(tempFilePath, Outlook.OlSaveAsType.olMSG);

                          }
                          catch (Exception ex)
                          {

                          }

                          Outlook.MAPIFolder fp = (Outlook.MAPIFolder)m.Parent;
                          DoNotMoveInNonDocLib(mailitemEntryID, fp);

                      }
                      catch (Exception)
                      {
                          NonDocMoveReportItem(Item);
                      }

                      MessageBox.Show("You are attempting to move files to a non document library. This action is not supported.", "ITOPIA", MessageBoxButtons.OK, MessageBoxIcon.Information);

                      return;

                  }

                  if (frmUploadItemsListObject == null || (frmUploadItemsListObject != null && frmUploadItemsListObject.IsDisposed == true))
                  {
                      //frmUploadItemsListObject = new frmUploadItemsList();

                      // myCustomTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(frmUploadItemsListObject, "ITOPIA");
                      //myCustomTaskPane.Visible = true;

                      IAddCustomTaskPane();

                  }
                  //frmUploadItemsListObject.TopLevel = true;
                  //frmUploadItemsListObject.TopMost = true;

                  ////////////////////// frmUploadItemsListObject.Show();

                  try
                  {

                      //////
                      //////////
                      Outlook.MailItem oMailItem = (Outlook.MailItem)Item;
                      parentfolder = (Outlook.MAPIFolder)oMailItem.Parent;
                      try
                      {
                          mailitem = oMailItem;

                          mailitemEntryID = oMailItem.EntryID;

                          string strsubject = oMailItem.EntryID;
                          if (string.IsNullOrEmpty(strsubject))
                          {
                              strsubject = "tempomailcopy";
                          }

                          mailitemEntryID = strsubject;

                          string tempFilePath = UserLogManagerUtility.RootDirectory + "\\" + strsubject + ".msg";

                          if (Directory.Exists(UserLogManagerUtility.RootDirectory) == false)
                          {
                              Directory.CreateDirectory(UserLogManagerUtility.RootDirectory);
                          }
                          oMailItem.SaveAs(tempFilePath, Outlook.OlSaveAsType.olMSG);

                      }
                      catch (Exception ex)
                      {

                      }

                      string fileName = string.Empty;
                      if (!string.IsNullOrEmpty(oMailItem.Subject))
                      {
                          //Replce any specila characters in subject
                          fileName = Regex.Replace(oMailItem.Subject, strMailSubjectReplcePattern, " ");
                          fileName = fileName.Replace(".", "_");
                      }

                      if (string.IsNullOrEmpty(fileName))
                      {
                          DateTime dtReceivedDate = Convert.ToDateTime(oMailItem.ReceivedTime);
                          fileName = "Untitled_" + dtReceivedDate.Day + "_" + dtReceivedDate.Month + "_" + dtReceivedDate.Year + "_" + dtReceivedDate.Hour + "_" + dtReceivedDate.Minute + "_" + dtReceivedDate.Millisecond;
                      }

                      UploadItemsData newUploadData = new UploadItemsData();
                      newUploadData.ElapsedTime = DateTime.Now;
                      newUploadData.UploadFileName = fileName;// oMailItem.Subject;
                      newUploadData.UploadFileExtension = ".msg";
                      newUploadData.UploadingMailItem = oMailItem;
                      newUploadData.UploadType = TypeOfUploading.Mail;
                      newUploadData.DisplayFolderName = folderName;
                      frmUploadItemsListObject.UploadUsingDelegate(newUploadData);
                      //Set dropped items is uploaded
                      /////////////////////////updated by Joy on 25.07.2012/////////////////////////////////
                      bool uploadStatus = frmUploadItemsListObject.IsSuccessfullyUploaded;
                      XMLLogOptions userOption = UserLogManagerUtility.GetUserConfigurationOptions();
                      if (uploadStatus == true)
                      {
                          // Globals.ThisAddIn.isTimerUploaded = true;
                          isDroppedItemUplaoded = true;

                          for (int i = 0; i <= activeDroppingFolder.Items.Count; i++)
                          {
                              try
                              {
                                  Outlook.MailItem me = (Outlook.MailItem)activeDroppingFolder.Items[i];

                                  if (me.EntryID == mailitemEntryID)
                                  {
                                      me.Categories.Remove(0);
                                      me.Categories = newCatName;
                                      me.Save();

                                      if (userOption.AutoDeleteEmails == true)
                                      {
                                          UserMailDeleteOption(mailitemEntryID, parentfolder);
                                      }
                                  }
                              }
                              catch (Exception ex)
                              {

                              }
                          }

                          frmUploadItemsListObject.lblPRStatus.Invoke(new updateProgresStatus(() =>
                          {
                              frmUploadItemsListObject.lblPRStatus.Text = Globals.ThisAddIn.no_of_t_item_uploaded.ToString() + " " + "of" + " " + Globals.ThisAddIn.no_of_pending_items_to_be_uploaded.ToString() + " " + "Uploaded";
                          }));
                          frmUploadItemsListObject.progressBar1.Invoke(new updateProgessBar(() =>
                          {
                              frmUploadItemsListObject.progressBar1.Value = (((Globals.ThisAddIn.no_of_t_item_uploaded * 100 / Globals.ThisAddIn.no_of_pending_items_to_be_uploaded)));
                          }));

                      }
                      else
                      {
                          isDroppedItemUplaoded = false;
                      }

                      /////////////////////////updated by Joy on 25.07.2012/////////////////////////////////
                  }
                  catch (Exception ex)
                  {
                      isDroppedItemUplaoded = MoveItemIsReportItem(Item);
                  }

                  try
                  {
                      if (isDroppedItemUplaoded == false)
                      {
                          //string tempName = oDocItem.Subject;
                          string tempName = string.Empty;
                          Outlook.DocumentItem oDocItem = (Outlook.DocumentItem)Item;

                          try
                          {

                              Outlook._MailItem myMailItem = (Outlook.MailItem)addinExplorer.Selection[1];
                              foreach (Outlook.Attachment oAttachment in myMailItem.Attachments)
                              {
                                  if (oAttachment.FileName == oDocItem.Subject)
                                  {
                                      tempName = oAttachment.FileName;
                                      tempName = tempName.Substring(tempName.LastIndexOf("."));
                                      oAttachment.SaveAsFile(UserLogManagerUtility.RootDirectory + @"\tempattachment" + tempName);

                                      //Read file data to bytes
                                      //byte[] fileBytes = File.ReadAllBytes(UserLogManagerUtility.RootDirectory + @"\tempattachment" + tempName);
                                      System.IO.FileStream Strm = new System.IO.FileStream(UserLogManagerUtility.RootDirectory + @"\tempattachment" + tempName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                                      System.IO.BinaryReader reader = new System.IO.BinaryReader(Strm);
                                      byte[] fileBytes = reader.ReadBytes(Convert.ToInt32(Strm.Length));
                                      reader.Close();
                                      Strm.Close();

                                      //Replace any special characters are there in file name
                                      string fileName = Regex.Replace(oAttachment.FileName, strAttachmentReplacePattern, " ");

                                      //Add uplaod attachment item data to from list.
                                      UploadItemsData newUploadData = new UploadItemsData();
                                      newUploadData.UploadType = TypeOfUploading.Attachment;
                                      newUploadData.AttachmentData = fileBytes;
                                      newUploadData.DisplayFolderName = activeDroppingFolder.Name;

                                      if (fileName.Contains("."))
                                      {
                                          newUploadData.UploadFileName = fileName.Substring(0, fileName.LastIndexOf("."));
                                          newUploadData.UploadFileExtension = fileName.Substring(fileName.LastIndexOf("."));

                                          if (string.IsNullOrEmpty(newUploadData.UploadFileName.Trim()))
                                          {
                                              //check file name conatins empty add the date time
                                              newUploadData.UploadFileName = "Untitled_" + DateTime.Now.ToFileTime();

                                          }
                                      }

                                      //Add to form
                                      frmUploadItemsListObject.UploadUsingDelegate(newUploadData);
                                      //Set dropped mail attachment items is uploaded.
                                      isDroppedItemUplaoded = true;
                                      newUploadData = null;
                                      //oDocItem.Delete();
                                      break;
                                  }
                              }
                          }
                          catch (InvalidCastException ex)
                          {
                              //Set dropped mail attachment items is uploaded to false
                              isDroppedItemUplaoded = false;
                          }

                          if (isDroppedItemUplaoded == false)
                          {
                              tempName = oDocItem.Subject;
                              tempName = tempName.Substring(tempName.LastIndexOf("."));
                              oDocItem.SaveAs(UserLogManagerUtility.RootDirectory + @"\tempattachment" + tempName, Type.Missing);

                              System.IO.FileStream Strm = new System.IO.FileStream(UserLogManagerUtility.RootDirectory + @"\tempattachment" + tempName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                              System.IO.BinaryReader reader = new System.IO.BinaryReader(Strm);
                              byte[] fileBytes = reader.ReadBytes(Convert.ToInt32(Strm.Length));
                              reader.Close();
                              Strm.Close();

                              //Replace any special characters are there in file name
                              string fileName = Regex.Replace(oDocItem.Subject, strAttachmentReplacePattern, " ");

                              //Add uplaod attachment item data to from list.
                              UploadItemsData newUploadData = new UploadItemsData();
                              newUploadData.UploadType = TypeOfUploading.Attachment;
                              newUploadData.AttachmentData = fileBytes;
                              newUploadData.DisplayFolderName = activeDroppingFolder.Name;

                              if (fileName.Contains("."))
                              {
                                  newUploadData.UploadFileName = fileName.Substring(0, fileName.LastIndexOf("."));
                                  newUploadData.UploadFileExtension = fileName.Substring(fileName.LastIndexOf("."));

                                  if (string.IsNullOrEmpty(newUploadData.UploadFileName.Trim()))
                                  {
                                      //check file name conatins empty add the date time
                                      newUploadData.UploadFileName = "Untitled_" + DateTime.Now.ToFileTime();

                                  }
                              }

                              //Add to form
                              frmUploadItemsListObject.UploadUsingDelegate(newUploadData);
                              newUploadData = null;
                              //oDocItem.Delete();
                          }

                      }
                  }
                  catch (Exception ex)
                  {
                      //throw ex;
                      //////////////////////////////updated by Joy on 28.07.2012///////////////////////////////////
                      //  EncodingAndDecoding.ShowMessageBox("FolderItem Add Event_DocItem Conv", ex.Message, MessageBoxIcon.Error);
                      //////////////////////////////updated by Joy on 28.07.2012///////////////////////////////////
                  }

                  try
                  {
                      XMLLogOptions userOptions = UserLogManagerUtility.GetUserConfigurationOptions();

                      for (int i = 0; i <= parentfolder.Items.Count; i++)
                      {
                          try
                          {
                              Outlook.MailItem me = (Outlook.MailItem)parentfolder.Items[i];

                              if (me.EntryID == mailitemEntryID)
                              {
                                  ///////////////////////////modified by Joy on 10.08.2012////////////////////////////////////

                                  if (isDroppedItemUplaoded == true)
                                  {

                                      me.Categories.Remove(0);
                                      me.Categories = newCatName;
                                      me.Save();
                                      if (userOptions.AutoDeleteEmails == true)
                                      {
                                          UserMailDeleteOption(mailitemEntryID, parentfolder);
                                      }
                                      //parentfolder.Items.Remove(i);
                                  }
                                  ///////////////////////////modified by Joy on 10.08.2012////////////////////////////////////

                              }
                          }
                          catch (Exception)
                          {

                          }
                      }
                  }

                  catch (Exception)
                  {

                  }
                  if (!string.IsNullOrEmpty(mailitemEntryID))
                  {
                      if (ItemType == TypeOfMailItem.ReportItem)
                      {
                          UserReportItemDeleteOption(mailitemEntryID, parentfolder);
                      }
                      else
                      {
                          ///////////////////////////Updated by Joy on 16.08.2012....to be updated later///////////////////////////////
                          // UserMailDeleteOption(mailitemEntryID, parentfolder);
                          ///////////////////////////Updated by Joy on 16.08.2012....to be updated later///////////////////////////////
                      }
                  }

              }

              }
              catch (Exception ex)
              {
              EncodingAndDecoding.ShowMessageBox("Folder Item Add Event", ex.Message, MessageBoxIcon.Error);

              }

              //AddToUploadList(Item);
        }
        private List <Outlook.ContactItem> GetListOfContacts(Outlook._Application Application)
        {
            List <Outlook.ContactItem> contactItemsList = null;

            Outlook.Items      folderItems             = null;
            Outlook.MAPIFolder folderSuggestedContacts = null;
            Outlook.NameSpace  ns             = null;
            Outlook.MAPIFolder folderContacts = null;
            object             itemObj        = null;

            try
            {
                contactItemsList = new List <Outlook.ContactItem>();
                ns = Application.GetNamespace("MAPI");
                // getting items from the Contacts folder in Outlook
                folderContacts = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
                folderItems    = folderContacts.Items;
                for (int i = 1; folderItems.Count >= i; i++)
                {
                    itemObj = folderItems[i];
                    if (itemObj is Outlook.ContactItem)
                    {
                        contactItemsList.Add(itemObj as Outlook.ContactItem);
                    }
                    else
                    {
                        Marshal.ReleaseComObject(itemObj);
                    }
                }
                Marshal.ReleaseComObject(folderItems);
                folderItems = null;
                //// getting items from the Suggested Contacts folder in Outlook
                //folderSuggestedContacts = ns.GetDefaultFolder(
                //                          Outlook.OlDefaultFolders.olFolderSuggestedContacts);
                //folderItems = folderSuggestedContacts.Items;
                //for (int i = 1; folderItems.Count >= i; i++)
                //{
                //    itemObj = folderItems[i];
                //    if (itemObj is Outlook.ContactItem)
                //        contactItemsList.Add(itemObj as Outlook.ContactItem);
                //    else
                //        Marshal.ReleaseComObject(itemObj);
                //}
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                if (folderItems != null)
                {
                    Marshal.ReleaseComObject(folderItems);
                }
                if (folderContacts != null)
                {
                    Marshal.ReleaseComObject(folderContacts);
                }
                if (folderSuggestedContacts != null)
                {
                    Marshal.ReleaseComObject(folderSuggestedContacts);
                }
                if (ns != null)
                {
                    Marshal.ReleaseComObject(ns);
                }
            }
            return(contactItemsList);
        }
Exemple #11
0
 public MailManager()
 {
     _app = new Outlook.Application();
     mail = (Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);
 }
		public OutlookContactsProvider(IGUICallbacks host, SyncEngine syncEngine)
		{
			owner = host;

			outlookApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
			Microsoft.Office.Interop.Outlook.NameSpace ns = outlookApp .GetNamespace("MAPI");
			nsObject = ns.MAPIOBJECT;

			if (!IsRedemptionInstalled())
			{
				Process reg = new Process();
				reg.StartInfo.FileName = "regsvr32.exe";
				reg.StartInfo.Arguments = "/s Redemption.dll";
				reg.StartInfo.UseShellExecute = false;
				reg.StartInfo.CreateNoWindow = true;
				reg.StartInfo.RedirectStandardOutput = true;
				reg.Start();
				reg.WaitForExit();
				reg.Close();
			}
			else
			{
			}

			rdoSession = new RDOSessionClass();
			try
			{
				rdoSession.MAPIOBJECT = nsObject;
			}
			catch
			{
				Microsoft.Office.Interop.Outlook.MAPIFolder mf = outlookApp.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
				string pstPath = GetStorePath(mf.StoreID);
				//string pstPath = @"C:\Users\maxim\AppData\Local\Microsoft\Outlook\Outlook.pst";
				rdoSession.LogonPstStore(pstPath, 1, "", "", 0);
			}
			
			rdoAddressBook = rdoSession.AddressBook;
			rdoAddressList = rdoAddressBook.GAL;
			rdoFld = rdoSession.GetDefaultFolder(rdoDefaultFolders.olFolderContacts);
			rdoItems = rdoFld.Items;

			this.syncEngine = syncEngine;
		}
Exemple #13
0
 public OutlookApplication(Outlook._Application application)
 {
     _app = application;
 }