none
Problems when adding in attach an html file RRS feed

  • Question

  • I have a C++ unmanaged code that open the outlook and create a new email and add some file to the attach files.

    All this works well except for html files when email format is “Html”. In this case html attach files are embedded in mail body (no other file is embedded in body email).

    I have the following code:        

    _Application olApp;

    Attachments myAttachments;

    // Prepare a new mail message

    _MailItem olMail = olApp.CreateItem(0);

    myAttachments = olMail.GetAttachments();

                 

    // inserir attachments

    for(int i=0; i<icl_attachmentsListFiles.GetCount(); i++)

    {

       COleVariant oAttachLocation(icl_attachmentsListFiles[i]);

       COleVariant oAttachDisplayName("egrou#cod_revs_id#"+icl_attachmentsListIds[i]);

       myAttachments.Add(oAttachLocation,  covOptional,  covOptional, oAttachDisplayName);

    }

    olMail.SetSubject(is_mailSubject);

    olMail.Display(COleVariant((short)FALSE));

    Wednesday, April 16, 2014 2:33 PM

Answers

  • I am testing in Outlook2010, but the problem happens in 2003 and 2013 too.

    I already found a solution.

    I just changed the order of some code. I am now adding the attach after doing the email Display and now works well.

    Thanks & Regards,

    Rui

    Wednesday, April 16, 2014 3:44 PM

All replies

  • Hello Rui,

    I'd recommend to specify all arguments explicitly, not to use defaults.

    The Add method accepts four parameters. One of them is the Position parameter which allows to hide the attachments, not to display it in the body. This parameter applies only to e-mail messages using the Rich Text format: it is the position where the attachment should be placed within the body text of the message. You just need to pass 0. I.e. a value of 0 makes the attachment hidden. Is this the case?

    Also I'd suggest specifying the Type parameter explicitly.

    BTW What Outlook version do you have installed on the PC?


    Wednesday, April 16, 2014 2:43 PM
  • Hi Eugene,

    As said in your link

    http://msdn.microsoft.com/en-us/library/office/ff869553%28v=office.15%29.aspx

    This paramenter only works for RichText, and my problem is when in Html format

    "This parameter applies only to e-mail messages using the Rich Text format".

    When and an html file in attach the hatml file text appears as text in email body, and the worst happen when the html file is in Unicode format. In this cases the html text appears in really strange caracters (like chinese characters)

    Here some text like appears

    㰀栀琀洀氀 砀洀氀渀猀㨀瘀㴀甀爀渀㨀猀挀栀攀洀愀猀洀椀挀爀漀猀漀昀琀挀漀洀㨀瘀洀氀ഀ਀砀洀氀渀猀㨀漀㴀甀爀渀㨀猀挀栀攀洀愀猀洀椀挀爀漀猀漀昀琀挀漀洀㨀漀昀昀椀挀攀㨀漀昀昀椀挀攀ഀ਀砀洀氀渀猀㨀眀㴀甀爀渀㨀猀挀栀攀洀愀猀洀椀挀爀漀猀漀昀琀挀漀洀㨀漀昀昀椀挀攀㨀眀漀爀

     

    Wednesday, April 16, 2014 3:03 PM
  • Hello Rui,

    I am aware that parameter play the key role only in case of Rich Text. It looks like you forgot to answer on my question: What Outlook version do you have installed on the PC?

    Do you have any other add-ins installed for Outlook?

    Did you try to reproduce the issue using a VBA macro? Does it work?

    Wednesday, April 16, 2014 3:37 PM
  • I am testing in Outlook2010, but the problem happens in 2003 and 2013 too.

    I already found a solution.

    I just changed the order of some code. I am now adding the attach after doing the email Display and now works well.

    Thanks & Regards,

    Rui

    Wednesday, April 16, 2014 3:44 PM
  • Good news!

    Thank you for letting us know.

    Wednesday, April 16, 2014 4:18 PM