none
Saveas Method for Outlook 2007 C# do not save reply mail on the c:\ RRS feed

  • Question

  • Hi,

         Since few days I try to make a plugin to save an selected email to my documents on the C:\.

    For now I could saveas email with or without attach files, from any folder in my old pst or in my ost.

    But, if I select a email in my inbox who are a anwser with the RE: in the subject, I could not save this email on my drive.

    If the saveas command work, I find a 0ko file white RE like name and without any extension in my documents folder. 

    Do you have another method to saveas a reply email ?

    thank's

    emarck

    Here is my code who select mail and try to saveas:

    Outlook.

    ExplorercurrExplorer = Application.ActiveExplorer();

         Outlook.

    Inspectoremail_select;

         email_select = Application.ActiveInspector();

       

    if(null!= currExplorer)

        {

            Outlook.

    Selectionselections = currExplorer.Selection;

           

    if(null!= selections && selections.Count > 0)

            {

               

    for(inti = 0; i <= selections.Count; ++i)

                {

                   

    objectselectedItem = (object)selections;

                   

    Int32compteur_selection = i+1;

                   

    if(Application.ActiveExplorer().Selection.Count > 0)

                    {

                       

    ObjectselObject = Application.ActiveExplorer().Selection[compteur_selection];

                    

                     

                       

    if(selObject isOutlook.MailItem)

                        {

                           

                            mailItem = (selObject

    asOutlook.MailItem);

                            sujet = mailItem.Subject;

                            date_heure = mailItem.ReceivedTime.ToShortDateString();

                            expediteur = mailItem.SenderName;

                           

    //pop-up contenant le sujet du courriel sélectionné.


                           

    MessageBox.Show(expediteur + sujet + " "+ date_heure);

                          

    //mailItem.SaveAs(@"C:\Users\martre.VILLERN\Downloads");


                           

                           

                            mailItem.SaveAs (

    @"C:\Users\martre.VILLERN\Downloads\"+ sujet + ".msg", Outlook.OlSaveAsType.olMSG );

                       

                        }

     

      

    Wednesday, June 12, 2013 4:36 PM

Answers

  • There should be no reason for a reply email or certain words in the subject should prevent saving an item, unless there are forbidden characters in the text you try to set as the file name. Otherwise there should be no problems.
     
    For Windows illegal characters see http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx. Are you removing any ":" characters in the file name?

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Emarck" <=?utf-8?B?RW1hcmNr?=> wrote in message news:cdb50233-1c0c-43d3-b66c-adce61accea9...

    Hi,

         Since few days I try to make a plugin to save an selected email to my documents on the C:\.

    For now I could saveas email with or without attach files, from any folder in my old pst or in my ost.

    But, if I select a email in my inbox who are a anwser with the RE: in the subject, I could not save this email on my drive.

    If the saveas command work, I find a 0ko file white RE like name and without any extension in my documents folder. 

    Do you have another method to saveas a reply email ?

    thank's

    emarck

    Here is my code who select mail and try to saveas:

    Outlook.

    ExplorercurrExplorer = Application.ActiveExplorer();

         Outlook.

    Inspectoremail_select;

         email_select = Application.ActiveInspector();

       

    if(null!= currExplorer)

        {

            Outlook.

    Selectionselections = currExplorer.Selection;

           

    if(null!= selections && selections.Count > 0)

            {

               

    for(inti = 0; i <= selections.Count; ++i)

                {

                   

    objectselectedItem = (object)selections;

                   

    Int32compteur_selection = i+1;

                   

    if(Application.ActiveExplorer().Selection.Count > 0)

                    {

                       

    ObjectselObject = Application.ActiveExplorer().Selection[compteur_selection];

                    

                     

                       

    if(selObject isOutlook.MailItem)

                        {

                           

                            mailItem = (selObject

    asOutlook.MailItem);

                            sujet = mailItem.Subject;

                            date_heure = mailItem.ReceivedTime.ToShortDateString();

                            expediteur = mailItem.SenderName;

                           

    //pop-up contenant le sujet du courriel sélectionné.


                           

    MessageBox.Show(expediteur + sujet + " "+ date_heure);

                          

    //mailItem.SaveAs(@"C:\Users\martre.VILLERN\Downloads");


                           

                           

                            mailItem.SaveAs (

    @"C:\Users\martre.VILLERN\Downloads\"+ sujet + ".msg", Outlook.OlSaveAsType.olMSG );

                       

                        }

     

      


    Ken Slovak MVP - Outlook
    • Marked as answer by Emarck Wednesday, June 12, 2013 8:31 PM
    Wednesday, June 12, 2013 5:37 PM
    Moderator

All replies

  • There should be no reason for a reply email or certain words in the subject should prevent saving an item, unless there are forbidden characters in the text you try to set as the file name. Otherwise there should be no problems.
     
    For Windows illegal characters see http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx. Are you removing any ":" characters in the file name?

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Emarck" <=?utf-8?B?RW1hcmNr?=> wrote in message news:cdb50233-1c0c-43d3-b66c-adce61accea9...

    Hi,

         Since few days I try to make a plugin to save an selected email to my documents on the C:\.

    For now I could saveas email with or without attach files, from any folder in my old pst or in my ost.

    But, if I select a email in my inbox who are a anwser with the RE: in the subject, I could not save this email on my drive.

    If the saveas command work, I find a 0ko file white RE like name and without any extension in my documents folder. 

    Do you have another method to saveas a reply email ?

    thank's

    emarck

    Here is my code who select mail and try to saveas:

    Outlook.

    ExplorercurrExplorer = Application.ActiveExplorer();

         Outlook.

    Inspectoremail_select;

         email_select = Application.ActiveInspector();

       

    if(null!= currExplorer)

        {

            Outlook.

    Selectionselections = currExplorer.Selection;

           

    if(null!= selections && selections.Count > 0)

            {

               

    for(inti = 0; i <= selections.Count; ++i)

                {

                   

    objectselectedItem = (object)selections;

                   

    Int32compteur_selection = i+1;

                   

    if(Application.ActiveExplorer().Selection.Count > 0)

                    {

                       

    ObjectselObject = Application.ActiveExplorer().Selection[compteur_selection];

                    

                     

                       

    if(selObject isOutlook.MailItem)

                        {

                           

                            mailItem = (selObject

    asOutlook.MailItem);

                            sujet = mailItem.Subject;

                            date_heure = mailItem.ReceivedTime.ToShortDateString();

                            expediteur = mailItem.SenderName;

                           

    //pop-up contenant le sujet du courriel sélectionné.


                           

    MessageBox.Show(expediteur + sujet + " "+ date_heure);

                          

    //mailItem.SaveAs(@"C:\Users\martre.VILLERN\Downloads");


                           

                           

                            mailItem.SaveAs (

    @"C:\Users\martre.VILLERN\Downloads\"+ sujet + ".msg", Outlook.OlSaveAsType.olMSG );

                       

                        }

     

      


    Ken Slovak MVP - Outlook
    • Marked as answer by Emarck Wednesday, June 12, 2013 8:31 PM
    Wednesday, June 12, 2013 5:37 PM
    Moderator
  • Hi !

            I have remove de : and all works great.

    thank you !

    Emarck

    • Marked as answer by Emarck Wednesday, June 12, 2013 8:30 PM
    • Unmarked as answer by Emarck Wednesday, June 12, 2013 8:31 PM
    Wednesday, June 12, 2013 6:14 PM
  • Better use the below function. It would take care of other special characters as well.

    string tempDir = Environment.GetEnvironmentVariable("TEMP");
    string tempMsgFile = tempDir + "\\" + selCount + "_" + String.Join(" ", mailItem.Subject.Split(Path.GetInvalidFileNameChars())) + ".msg";
    
    
    



    Monday, June 20, 2016 4:45 AM