Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. stuck on a problem with outlook and c#

stuck on a problem with outlook and c#

Scheduled Pinned Locked Moved C#
questionhelpcsharpdatabase
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ekynox
    wrote on last edited by
    #1

    g'day guys, i am stuck on a small problem which is starting to frustrate me a little. I have written a small c# application which displays a list of files. When a user selects one or more of the files it gets the selected files sends the file UNC path as hyper links to the email. The program itself invokes outlook to generate the emails. If I were to simply use the generic outlook email editor (i.e. not ms word), it works fine. I have included a fragment of my code at the bottom. The problem arises when outlook is configured to use ms word as the default email editor. There is no link being displayed in the body of the email. So I decided to write the content of the HTMLBody to console. What I found was that the link i am inserting using the tags is sitting out side the & tags. To totally contridict my findings, I reverted the outlook email editor to Outlook's own editor (ie. not using ms word). I examined the contents of oMailItem.HTMLBody via console. My reference file enclosed in the tags was sitting outside the tags. But the email itself showed the file as hyperlinks. I dont understand why this is possible!!!! :confused: :confused: My question is how do I insert the reference file link within the tags of the email body in c#??? At this point I am completely stumped. :confused: Is there a solution that can suit either types of email editors in outlook ???? Any suggestions ???? thanks private void createEmail(object sender, System.EventArgs e) { string PostingNotice =""; string EmailBody=""; string sHtml=""; oApp = new Outlook.Application(); oNameSpace= oApp.GetNamespace("MAPI"); oNameSpace.Logon(null,null,false,true); oOutlookFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail); Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); oMailItem.Display(false); foreach (ListViewItem lvitem in listView3.Items) { int index = int.Parse(lvitem.Index.ToString()); string filename = selectedFileArrayList[index].ToString(); int lastindex = filename.LastIndexOf('\\'); string displayFilename = filename.Substring(lastindex+1, ((filename.Length) - (lastindex+1))); //assume fileUNCPath as a string variable containing the UNC path of the file sHtml = "["+displayFilename+"](+)\n"+" \n"; oMailItem.HTMLBody = sHtml + oMailItem.HTMLBody; //append f

    C 1 Reply Last reply
    0
    • E ekynox

      g'day guys, i am stuck on a small problem which is starting to frustrate me a little. I have written a small c# application which displays a list of files. When a user selects one or more of the files it gets the selected files sends the file UNC path as hyper links to the email. The program itself invokes outlook to generate the emails. If I were to simply use the generic outlook email editor (i.e. not ms word), it works fine. I have included a fragment of my code at the bottom. The problem arises when outlook is configured to use ms word as the default email editor. There is no link being displayed in the body of the email. So I decided to write the content of the HTMLBody to console. What I found was that the link i am inserting using the tags is sitting out side the & tags. To totally contridict my findings, I reverted the outlook email editor to Outlook's own editor (ie. not using ms word). I examined the contents of oMailItem.HTMLBody via console. My reference file enclosed in the tags was sitting outside the tags. But the email itself showed the file as hyperlinks. I dont understand why this is possible!!!! :confused: :confused: My question is how do I insert the reference file link within the tags of the email body in c#??? At this point I am completely stumped. :confused: Is there a solution that can suit either types of email editors in outlook ???? Any suggestions ???? thanks private void createEmail(object sender, System.EventArgs e) { string PostingNotice =""; string EmailBody=""; string sHtml=""; oApp = new Outlook.Application(); oNameSpace= oApp.GetNamespace("MAPI"); oNameSpace.Logon(null,null,false,true); oOutlookFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail); Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); oMailItem.Display(false); foreach (ListViewItem lvitem in listView3.Items) { int index = int.Parse(lvitem.Index.ToString()); string filename = selectedFileArrayList[index].ToString(); int lastindex = filename.LastIndexOf('\\'); string displayFilename = filename.Substring(lastindex+1, ((filename.Length) - (lastindex+1))); //assume fileUNCPath as a string variable containing the UNC path of the file sHtml = "["+displayFilename+"](+)\n"+" \n"; oMailItem.HTMLBody = sHtml + oMailItem.HTMLBody; //append f

      C Offline
      C Offline
      codeprojectin
      wrote on last edited by
      #2

      You are prefixing the sHtml text before the oMailItem.HTMLBody which naturally lands up before the html part which includes .. Try using oMailItem.Body = sHtml; oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;

      E 1 Reply Last reply
      0
      • C codeprojectin

        You are prefixing the sHtml text before the oMailItem.HTMLBody which naturally lands up before the html part which includes .. Try using oMailItem.Body = sHtml; oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;

        E Offline
        E Offline
        ekynox
        wrote on last edited by
        #3

        thanks for replying.. but i dont quite understand your suggestion. I did try it out but it didnt make any different. I dont understand why would you want to do this : oMailItem.Body = sHtml; The way I understand is that Body simply indicates the plain text. What if your email contains a signature and the signature has an image as well. then you are loosing this image. Do you think you could explain it a bit more. What I was thinking is that instead of sHtml being assigned to HTMLBody when the sHtml string is created. Instead keep appending hyperlinks to the sHtml. Once the FOR loop finishes then do the following: oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML; signature = oMailItem.HTMLBody; //extract signature Console.WriteLine(signature); oMailItem.Body=""; oMailItem.Body+=sHtml; oMailItem.HTMLBody=oMailItem.Body+signature; With the above i am still loosing the image in the signature.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups