stuck on a problem with outlook and c#
-
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
-
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
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;
-
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;
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.