C# how to CC myself

I'm working on a VSTO project for Outlook. Very simple application with an icon on the ribbon. When user clicks on it, the selected email will be sent to the manager. It is working with the following code. But I want to add the sender as CC in the email. So whenever user clicks on it, the selected email will be sent to the manager and the user will be CC'd on it. So user will get a copy too. How can I CC the sender? here is the code:

public partial class Ribbon1
{
    private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
    {

    }

    private void button1_Click(object sender, RibbonControlEventArgs e)
    {
        Outlook.Application application = new Outlook.Application();
        Outlook.NameSpace ns = application.GetNamespace("MAPI");

        try
        {
            //get selected mail item
            Object selectedObject = application.ActiveExplorer().Selection[1];
            Outlook.MailItem selectedMail = (Outlook.MailItem)selectedObject;

            //create message
            Outlook.MailItem newMail = application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
            newMail.To = "email@gmail.com";
            newMail.CC = Outlook.Account;

            newMail.Subject = "Subject Here";
            newMail.Attachments.Add(selectedMail, Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem);

            newMail.Send();
            selectedMail.Delete();

            System.Windows.Forms.MessageBox.Show("Message has been sent! You have been CC'd.");
        }
        catch
        {
            System.Windows.Forms.MessageBox.Show("You must select a message to report.");
        }
    }
}

}



from Recent Questions - Stack Overflow https://ift.tt/3y4lVL3
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation