none
outlook Rtf format mail attachment problem RRS feed

  • Question

  • i am a beginner office developer and i was developing a outlook AddIn solution  and in that solution i show to the user the inspector window (where the RTF format for the mail item is chosen by default) and a menu which contain items the user can add any of them to the inspector window and these items later i will replace it  through the code by values from the database.

    the problem is that when the user add attachment to the inspector window as an icon and the position of this attachment is between the words of the mail item and later when i use the code to replace the placeholders data by the database values i find that the position of the attached file icon is placed at the end of the mail not in the same position the user put it in the inspector window 

    in the code i use  the position attribute to try control the position of the attached file shown as icon 

     (MailMergeItem as Outlook.MailItem).Attachments[1].Position = 10;

    but is failed to set the position as i want to be

    even for test  when i try to create a Rtf format mail item from scratch programmatically as in the following code and i want  to set  the position of the attachment file icon in some position it was failed also and the file placed at the end of the mail

                         MailMergeItem = Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                        (MailMergeItem as Outlook.MailItem).BodyFormat = Outlook.OlBodyFormat.olFormatRichText;
                        (MailMergeItem as Outlook.MailItem).To = "person@domain.com";
                        (MailMergeItem as Outlook.MailItem).Body = "mail    data ";
                        OpenFileDialog attachment = new OpenFileDialog();
                        attachment.Title = "Select a file to send";
                        attachment.ShowDialog();
                        if (attachment.FileName.Length > 0)
                        {
                            (MailMergeItem as Outlook.MailItem).Attachments.Add(
                                attachment.FileName,
                                Outlook.OlAttachmentType.olByValue  ,
                                6,
                                attachment.FileName);                      
                        }




    Wednesday, July 13, 2011 10:22 PM

Answers

  • Positioning the attachment can only be done when the attachment is added. After that the property is pretty much ignored. It's also not foolproof even when adding an attachment.
     
    A better question is why use RTF format at all? HTML is far more standard and more editable, and every modern mail client can handle HTML emails. Only Outlook and Eudora can read RTF emails, others get a plain text message with a winmail.dat attachment. Even with that, sending RTF over the Internet is problematic at best and depends on settings both in Outlook and your Exchange server if you have one, plus settings on each contact item.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "dev010101" <=?utf-8?B?ZGV2MDEwMTAx?=> wrote in message news:9d2012f2-3e10-4dc9-9b7c-7549389ff3cd...

    i am a beginner office developer and i was developing a outlook AddIn solution  and in that solution i show to the user the inspector window (where the RTF format for the mail item is chosen by default) and a menu which contain items the user can add any of them to the inspector window and these items later i will replace it  through the code by values from the database.

    the problem is that when the user add attachment to the inspector window as an icon and the position of this attachment is between the words of the mail item and later when i use the code to replace the placeholders data by the database values i find that the position of the attached file icon is placed at the end of the mail not in the same position the user put it in the inspector window 

    in the code i use  the position attribute to try control the position of the attached file shown as icon 

     (MailMergeItem as Outlook.MailItem).Attachments[1].Position = 10;

    but is failed to set the position as i want to be

    even for test  when i try to create a Rtf format mail item from scratch programmatically as in the following code and i want  to set  the position of the attachment file icon in some position it was failed also and the file placed at the end of the mail

                         MailMergeItem = Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                        (MailMergeItem as Outlook.MailItem).BodyFormat = Outlook.OlBodyFormat.olFormatRichText;
                        (MailMergeItem as Outlook.MailItem).To = "person@domain.com";
                        (MailMergeItem as Outlook.MailItem).Body = "mail    data ";
                        OpenFileDialog attachment = new OpenFileDialog();
                        attachment.Title = "Select a file to send";
                        attachment.ShowDialog();
                        if (attachment.FileName.Length > 0)
                        {
                            (MailMergeItem as Outlook.MailItem).Attachments.Add(
                                attachment.FileName,
                                Outlook.OlAttachmentType.olByValue  ,
                                6,
                                attachment.FileName);                      
                        }





    Ken Slovak MVP - Outlook
    Thursday, July 14, 2011 1:28 PM