Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
GeneralRe: method and parameters Pin
Member 137173709-Mar-18 0:47
Member 137173709-Mar-18 0:47 
GeneralRe: method and parameters Pin
OriginalGriff9-Mar-18 1:24
mveOriginalGriff9-Mar-18 1:24 
AnswerRe: method and parameters Pin
#realJSOP9-Mar-18 6:20
mve#realJSOP9-Mar-18 6:20 
AnswerRe: method and parameters Pin
Luc Pattyn9-Mar-18 9:20
sitebuilderLuc Pattyn9-Mar-18 9:20 
AnswerRe: method and parameters Pin
BillWoodruff10-Mar-18 18:43
professionalBillWoodruff10-Mar-18 18:43 
QuestionWPF: Groupbox background image Pin
Hervend8-Mar-18 19:12
Hervend8-Mar-18 19:12 
AnswerRe: WPF: Groupbox background image Pin
Richard MacCutchan8-Mar-18 20:58
mveRichard MacCutchan8-Mar-18 20:58 
QuestionEditing text in body of email via Outlook add-in Pin
Rakanoth8-Mar-18 0:03
Rakanoth8-Mar-18 0:03 
The following is an add-in for MS Outlook. One can scan the body of an e-mail and if there is a certain (specific word or pattern) word present, then a MessageBox appears. However, I am wondering if it is possible to change the way a word appears or to edit the text in the body of email, without MessageBox whatsoever. For example, a word (such as the name of the company) can be converted into an hyperlink (i.e. Google to www.google.com or Microsoft to www.microsoft.com) and the user who reads emails on Outlook always sees the hyperlink instead of the word itself.

<pre lang="c#">using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Drawing;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Text.RegularExpressions;


namespace FirstOutlookAddIn
{
    public partial class ThisAddIn
    {
        public static string[] data = new string[10];
        public static Stopwatch timer = new Stopwatch();
        Outlook.NameSpace outlookNameSpace;
        Outlook.MAPIFolder inbox;
        Outlook.Items items;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {

            timer = Stopwatch.StartNew(); ReadMail();
            outlookNameSpace = this.Application.GetNamespace("MAPI");
            inbox = outlookNameSpace.GetDefaultFolder(
                    Microsoft.Office.Interop.Outlook.
                    OlDefaultFolders.olFolderInbox);
            items = inbox.Items;

            items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(ReadSingleMail); // Modified method to run for single email

        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            // Hinweis: Outlook löst dieses Ereignis nicht mehr aus. Wenn Code vorhanden ist, der 
            // ausgeführt werden muss, wenn Outlook geschlossen wird, informieren Sie sich unter http://go.microsoft.com/fwlink/?LinkId=506785
        }

        static void ReadSingleMail(dynamic item)
        {
            string bodyText; // Email body
            string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); //Path to My Documents

            if (item != null)
            {
                bodyText = item.Body;
            }
            else
            {
                return; // If no e-mail body, exit function.
            }
        }

        static void ReadMail()
        {
            //Set up OCR
            string bodyText;
            string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            //Get unread emails from Inbox
            Microsoft.Office.Interop.Outlook.Application app = null;
            Microsoft.Office.Interop.Outlook._NameSpace ns = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
            app = new Microsoft.Office.Interop.Outlook.Application();
            ns = app.GetNamespace("MAPI");
            inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
            Outlook.Items unreadItems = inboxFolder.Items.Restrict("[Unread]=true");
            int max_runs;
            //Go through each Unread email
            if (unreadItems.Count > 10) { max_runs = 10; }
            else max_runs = unreadItems.Count;

            for (int counter = 1; counter <= max_runs; counter++)
            {
                //Reinitialize Data array
                for (int index = 0; index <= 8; index++)
                {
                    data[index] = "";
                }
                dynamic item = unreadItems[counter];
                bodyText = item.Body;
                Match match = Regex.Match(bodyText, "Insert searched pattern here");

                if (match.Success)
                {
                    MessageBox.Show(match.Value);
                    match = match.NextMatch();
                }

            }            
        }

        #region Von VSTO generierter Code

        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}

GeneralRe: Editing text in body of email via Outlook add-in Pin
Richard MacCutchan8-Mar-18 0:08
mveRichard MacCutchan8-Mar-18 0:08 
GeneralRe: Editing text in body of email via Outlook add-in Pin
Eddy Vluggen8-Mar-18 0:13
professionalEddy Vluggen8-Mar-18 0:13 
GeneralRe: Editing text in body of email via Outlook add-in Pin
Richard MacCutchan8-Mar-18 0:15
mveRichard MacCutchan8-Mar-18 0:15 
GeneralRe: Editing text in body of email via Outlook add-in Pin
Eddy Vluggen8-Mar-18 0:21
professionalEddy Vluggen8-Mar-18 0:21 
AnswerRe: Editing text in body of email via Outlook add-in Pin
Eddy Vluggen8-Mar-18 0:24
professionalEddy Vluggen8-Mar-18 0:24 
AnswerRe: Editing text in body of email via Outlook add-in Pin
Rakanoth8-Mar-18 22:48
Rakanoth8-Mar-18 22:48 
Questionhow can i set windows form over other programs at the desktop in c# Pin
galba20185-Mar-18 22:11
galba20185-Mar-18 22:11 
AnswerRe: how can i set windows form over other programs at the desktop in c# Pin
OriginalGriff5-Mar-18 22:31
mveOriginalGriff5-Mar-18 22:31 
AnswerRe: how can i set windows form over other programs at the desktop in c# PinPopular
Eddy Vluggen6-Mar-18 1:10
professionalEddy Vluggen6-Mar-18 1:10 
GeneralRe: how can i set windows form over other programs at the desktop in c# Pin
galba20186-Mar-18 2:00
galba20186-Mar-18 2:00 
GeneralRe: how can i set windows form over other programs at the desktop in c# Pin
Eddy Vluggen6-Mar-18 2:04
professionalEddy Vluggen6-Mar-18 2:04 
AnswerRe: how can i set windows form over other programs at the desktop in c# Pin
Gerry Schmitz6-Mar-18 6:07
mveGerry Schmitz6-Mar-18 6:07 
AnswerRe: how can i set windows form over other programs at the desktop in c# Pin
Dave Kreskowiak8-Mar-18 4:16
mveDave Kreskowiak8-Mar-18 4:16 
Questionapple push notification Pin
Member 108437285-Mar-18 20:22
Member 108437285-Mar-18 20:22 
AnswerRe: apple push notification Pin
Pete O'Hanlon5-Mar-18 20:28
mvePete O'Hanlon5-Mar-18 20:28 
GeneralRe: apple push notification Pin
Member 108437285-Mar-18 20:35
Member 108437285-Mar-18 20:35 
GeneralRe: apple push notification Pin
Pete O'Hanlon5-Mar-18 20:54
mvePete O'Hanlon5-Mar-18 20:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.