Resolved [Solved] My own little program

Peque

Member
Joined
Sep 14, 2023
Messages
15
Programming Experience
Beginner
Hi Forum

I'm started to look at learning C sharp - so quite a newbie for this but had some programming skills way back. Sorry the code is properly not high standard, and surely somethng could be done easier
So starting out with hear your input on how to do this, since I would like to gain more knowledge (and here its including C#) instead of looking out the Window :-(
I did after googling etc - found that information for creating the attached Macroes, to attach to my Ribbon, only where able to do use Microsoft symbols etc

My plan is to reply the active mailItem from Outlook (inbox with marked mail or have opened messages) in HTML - As I do in this Macro example.
But all 3button refers to the same action with different information, read from a text file - The action would be creating a reply to the acive Mailitem in Outlook.
This reply would be the same layout for all 3 with some information - along with a Picture - so That I'll properly creating using stringbuilder later on creating the Body with html.
Since the images are not created from the template, I'm instead thinking

But I cannot seem to find my way on getting the active windows - and create a reply for this - Like this macro does.
I would like to create the reply - but not sending it - But the position could be either Inbox or have the email opened by double click on the mail.

C#:
using Microsoft.Office.Interop.Outlook;
using Outlook = Microsoft.Office.Interop.Outlook;
using OutlookApp = Microsoft.Office.Interop.Outlook.Application;
using Microsoft.Office.Tools.Ribbon;
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace OutlookFWS
{

    public partial class Ribbon1
    {
        /// <summary>
        /// Knap 1 - Brabrand
        /// </summary>
        private void But1_Click(object sender, RibbonControlEventArgs e)
        {
            // setting the shop
            shop = "gs_Brabrand";
            try
            {
                getShop(shop);
            }
            catch (System.Exception ex)
            {
                _ = MessageBox.Show("Error: " + ex);
            }
        }
        private void getShop(string shop)
         {
             // Default strings in use
              Console.WriteLine("Starting Get shop Method");

              // Switch for getting Location of the shop
              switch (shop)
              {
                  case "gs_Brabrand":
                    // Setting target fullPath for Address information
                    fullPath = getShopString(shop);
                      System.Diagnostics.Debug.WriteLine(fullPath + " is the Address information."); // Just checking our returned value
                      // Sending for getting the full Path
                      GetCompany(fullPath);
                      // Create Reply
                      CreateReply((MailItem)orgMail);
                      break;
                    case "gs_Broendby":
                     case "gs_Broenderslev":
            }
          private string getShopString(string shop)
        {
            string fullPath = "C:\\Users\\" + Environment.UserName + "\\" + shop + ".txt";
            return fullPath;
        }

            public void CreateReply(MailItem mailItem)
            {
                Outlook.Inspector orgMail = null;
                var replyMail = mailItem.ReplyAll();
                replyMail.SendUsingAccount.Application.ActiveInspector();
                replyMail.Display();
            }
        }
    }
 

Attachments

  • VBA .txt
    1.7 KB · Views: 7

Latest posts

Back
Top Bottom