none
how to open Outlook from C#, and send email using attachment RRS feed

  • Question

  • I want to open Outlook by C# code,

    so send attachment using outlook , once open from C#.

    i ll pass To and Attachment details from code.

    Thanks

    A-


    Ashok

    • Moved by Cindy Meister MVP Friday, January 4, 2013 9:24 AM not using VSTO technology (From:Visual Studio Tools for Office)
    Thursday, January 3, 2013 8:48 PM

Answers

  • you have to have up to date antivirus installed on machine if you want to avoid that prompt.
    Friday, January 4, 2013 4:57 PM
  • i have found code but this code every time asking permission thing to allow user, i dont want to give message

    Outlook.

    Application oApp = new Outlook.Application();

    Outlook.

    MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem));

    #region

    set email recipients

    {

    email.Recipients.Add(

    "AM@Domain.com");

    }

    #endregion

    //email subject

    email.Subject =

    "Invoice # ";

    #region

    set email Text

    {

    string messageBody = "emailText.EmailText.ToString().Trim()";

    email.Body = messageBody;

    }

    #endregion

    #region

    email attachment

    {

    string fileName = "test.txt";

    string filePath = "C:\\";

    filePath = filePath + fileName ;

    int iPosition = (int)email.Body.Length + 1;

    int iAttachType = (int)Outlook.OlAttachmentType.olByValue;

    Outlook.

    Attachment oAttach = email.Attachments.Add(filePath, iAttachType, iPosition, fileName);

    }

    #endregion

    email.Display();


    Ashok

    Friday, January 4, 2013 2:21 PM

All replies

  • i have found code but this code every time asking permission thing to allow user, i dont want to give message

    Outlook.

    Application oApp = new Outlook.Application();

    Outlook.

    MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem));

    #region

    set email recipients

    {

    email.Recipients.Add(

    "AM@Domain.com");

    }

    #endregion

    //email subject

    email.Subject =

    "Invoice # ";

    #region

    set email Text

    {

    string messageBody = "emailText.EmailText.ToString().Trim()";

    email.Body = messageBody;

    }

    #endregion

    #region

    email attachment

    {

    string fileName = "test.txt";

    string filePath = "C:\\";

    filePath = filePath + fileName ;

    int iPosition = (int)email.Body.Length + 1;

    int iAttachType = (int)Outlook.OlAttachmentType.olByValue;

    Outlook.

    Attachment oAttach = email.Attachments.Add(filePath, iAttachType, iPosition, fileName);

    }

    #endregion

    email.Display();


    Ashok

    Friday, January 4, 2013 2:21 PM
  • you have to have up to date antivirus installed on machine if you want to avoid that prompt.
    Friday, January 4, 2013 4:57 PM