I have a Win Form application that does some boring accounting stuff and then sends it's data to some lucky recipients. I am using the Outlook 12.0 Interop objects and my applications environment ranges from office 2003 on XP to office 2007 on Win 7.
My issue lies with sending the corporate signature with the sent emails.
It contains two images and I would like to embed these images so they appear to be part of the body (assuming the receiving mail client supports that).
I have tried a few different methods of accomplishing this; but still no luck!
I have tried:
Extracting the html data from the signatures folder, changing the
html img tags src attribute to include 'file///'. This causes Outlook
to replace the 'file///' with 'CID' and I assumed it would also embed
the image... we should never assume :|. This is the method I found
worked best for getting the rest of the signature.
(After creating a new MailItem) - Grabbing the HTMLBody of the MailItem
and extracting the relevant part including the signature... This
didnt work due to the new MailItem object being very inconsistent
with it's signature. By that I mean sometimes the new item would
include the signature and sometimes it wouldn't! :s I cannot figure out why it is not always there, no other part of my code has changed!
I read on another post here about the GetInspector property... Apparently just calling this will do 'Some stuff' and the signature will magically appear in your mail item... NO!
Things I can't do:
I cannot (as much as i would like to) shove the images online
somewhere and point to them in the emails html.
I cannot use SMTP(It has to be through Outlook... sigh).
I am thinking that the best way seems to be my original method of messing about with the CID, but I do not really know much about what Outlook is doing in the background so I am having trouble figuring out what else I need to do to get the images sent along with the email.
Hoping someone out there has some idea about what I am doing wrong or what else I could try.
Please let me know if code would be helpful and I will post, (Most of the code tried is from this site... I just cannot find the links again and am trying to avoid making this question tooooo long).
Many thanks
This is not the most efficient or flexible solution you can use, but probably the most robust and portable. You can convert your image bitmap into plain HTML and embed that HTML in your e-mail signature.
The conversion is quite simple, you can use the utility I wrote (open source) here.
Related
I have a web page that uses a webmail service to send emails. This is on an company intranet using a Microsoft Exchange server. My website created an email with a link to an image handler on my website. In my code, I can print some debug messages and I see:
<img src='http://tav.target.com/VIBEHandler.ashx?id=z064441_45975&type=Amazing'/>
But in the email, when I view the source code, I see this:
<img src="http://tav.target.com/VIBEHandler.ashx?id=z064441_45975&type=Amazing"/>
My single quotes changed to double quotes (no big deal).
&
changed to
&
This causes the URL to not work and images appear as the red "x", indicating a missing image.
How can I preserve my URL?
Your 3rd party emailing service might be converting your HTML document to a valid XML document for compatibility reasons.
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
Basically, in XML, an ampersand character represents and XML entity, and can not be used unless you place the text within a CDATA node. Your 3rd party service seems to just be converting the & to & , which would work to safely display the value, but doesn't do too much for a URL.
http://www.w3schools.com/xml/xml_cdata.asp
If I were in your situation, I would URL encode the image URL when generating the HTML document that is being sent out. This way, it is both a proper link, and a valid XML string.
HttpUtility.UrlEncode(myUrlString);
http://msdn.microsoft.com/en-us/library/4fkewx0t%28v=vs.110%29.aspx
Hope this helps!
The best solution we could come up with is to use a single variable with multiple values separated with an underscore. This eliminates the need for the '&' symbol entirely and makes everything happy and compatible.
The URL is basically a link to an image handler so we can include images in emails without the use of attachments, shared drives, etc. The image handler can also do things like merge images together to create a single image (WAY better than trying to overlap images in emails which almost NEVER works). I simply added some code to the image handler that can check for and dissect the "meta-variable" in my URL.
http://sample.com?var=ONE_TWO_THREE
http://sample.com?var1=ONE&var2=TWO&var3=THREE
The URL now looks more clean and can have as many variables as I want so long as I put everything in the exact correct order, read it all in using the same sequence, don't miss anything, and document everything well. I COULD go one step farther and specify what each variable means:
http://sample.com?var=first-Nicolai_last-Dutka_age-34_etc-foobar
But that just tells the whole world what all my variables mean! Hypothetically, I could do:
http://sample.com?var=24154#kja&nl897q45pjkh8&&^HJ435
Then it would be up to me to determine where the breaking points are to bust that up into the variables:
24151, kja*, n1897, 45, etc
Of course, I'm not going to be that complex and will likely just stick to:
http://sample.com?var=ONE_TWO_THREE
Enjoy!
I need get the html code this site (with C#):
http://urbs-web.curitiba.pr.gov.br/centro/defmapalinhas.asp?l=n (only works with IE8)
Using the WebClient class, or HttpWebResquest, or any other library, I do not have access to the html code generated dynamically.
So my only solution (I guess) would be to use the WebBrowser Control (WPF).
I was trying and trying, using mshtml.HTMLDocument and SHDocVw.IWebBrowser2
but it is a mess, I can not find what I want on it
it seems there are many "iframe", and inside there are more "iframe".
I do not know, I tried:
IHTMLElementCollection elcol = htmlDoc.getElementsByTagName("iframe");
var test = htmlDoc.getElementsByTagName("HTML");
var test2 = doc.all;
but had no progress, does anyone know how to help me?
Observation / trivia: This is the site that shows where all bus pass in my city. This site is horrible, and only works in IE8 has serious problems. I would like to use this information to try to create a better service, using google maps or bing maps posteriorly.
The site that I was trying to get the information is no longer available, the idea to get dynamic html source code was abandoned and I cannot found the solution using a WebBrowser Control for WPF.
I believe that today there are other ways to solve this problem.
You need to use the "Frames" object in the WebBrowser control, this object collection will return all frames and iframes if I recall correctly, and you need to look at the frames collection for each newly discovered frame you find on the page, get me? So, it’s like a recursive discovery loop that you need to run, you add each frame you find to your array or collection, and for each "unsearched" frame, you must look at that frames ".Frames" collection (they will all have a .Count etc, just a typical collection) and you do this for every newly discovered frame that you find, until of course, there are no longer any newly discovered frames that haven't had their ".Frames" collection searched.
So, the function, if done as per above, will allow for infinitely nested frames to be discovered, as I've done this in a VB6 project (I'm happy to give you the source for it if you would like it). However, the nesting is not preserved in my example, but that is ok since the nesting structure isn't important and you should figure out which was what by the order of the frames that are added to the collection since the order is related to the hierarchy of the frames being added.
Once you do that, getting the html source on this is pretty straight forward and I’m sure you know how to do, probably a .DocumentText depending on the version of the WB control you are using.
Also, you say it is not possible to use the HTTP clients to directly grab the source code? I must disagree, since once you have the frame objects, you can get the URLs from each frame object and do a URL2String type call to get the URL and turn it into a string from any httpclient-like class or framework. The only way it may be prevented on their behalf if if they accept requests only from a particular referrer (ie: the referrer must be from their domain name on some of their files etc), or the USER_AGENT where if it isn't one of the specified browsers, then it is technically possible that they will reject and not return data, unlikely but possible.
However, both referrer and user_agent can be changed in the httpclient you are using, so if they are imposing limits based on this sort of stuff, you can spoof them very easily and give them the data that they expect. Once again, this is low probability stuff, but it is possible they may have set things up this way especially if their data is proprietary.
PS: My first visit to the site ended up in IE crashing and reopening that tab :), terrible site I agree.
I need my .NET desktop app to be able to send various HTML mails, allowing users to create custom templates, including images and possibly CSS style (if they copy/paste the HTML from other sources).
From what I've been reading, it's not that simple:
Images need to be embedded and their links replaced with content IDs
CSS styles containing images also need to be fixed
Background color/image won't work, it's better to wrap the mail in a table and apply the CSS to it
SMTP servers can interpret lines starting with a dot as "end of transmission", so at least a space must be added to all such lines
Who knows what else
My questions are:
Is there anything else I should take care of?
Is there a library which already does this so that I don't reinvent?
One thing I can think of, make use of Alternate views for those recipients whose mail clients can't/won't accept HTML emails (or they've got it turned off). That way they'll get a plain text version, in which you could include a link to an html version live on the web if they decide want to view it.
I have also heard that not including a plain text version increases your likelyhood of being marked as spam - this is due to the fact that many mail filters compare the plain text and html versions of a message; if they differ too wildly it's not a good sign for you :-)
Other spam indicators include html messages which have more pictures than text, and generally sloppy html - broken css, bad links, missing tags etc - consider using some sort of markup validator before sending.
I have found the following CodeProject article, which describes how to embed various image resources into the mail:
Sending the contents of a webpage with images as an HTML mail.
It has some useful examples, although it doesn't seem to include an alternate plain text view, so I will have to add that.
It's still a pity that no-one has put together a library which does this stuff automatically.
I was wondering if there is another way to spell check a Windows app instead what I've been of using: "Microsoft.Office.Interop.Word". I can't buy a spell checking add-on. I also cannot use open source and would like the spell check to be dynamic..any suggestions?
EDIT:
I have seen several similar questions, the problem is they all suggest using open source applications (which I would love) or Microsoft Word.
I am currently using Word to spell check and it slows my current application down and causes several glitches in my application. Word is not a clean solution so I'm really wanting to find some other way.. Is my only other option to recreate my app as a WPF app so I can take advantage of the SpellCheck Class?
If I were you I would download the data from the English Wiktionary and parse it to obtain a list of all English words (for instance). Then you could rather easily write at least a primitive spell-checker yourself. In fact, I use a parsed version of the English Wiktionary in my own mathematical application AlgoSim. If you'd like, I could send you the data file.
Update
I have now published a parsed word list at english.zip (942 kB, 383735 entries, zip). The data originates from the English Wiktionary, and as such, is licensed under the Creative Commons Attribution/Share-Alike License.
To obtain a list like this, you can either download all articles on Wiktionary as a huge XML file containing all Wiki- and HTML-formatted articles. This is then more or less trivial to parse. Alternatively, you can run a bot on the site. I got help to obtain a parsed file from a user at Wiktionary (I seem to have forgotten his name, though...), and this file (english.txt in english.zip) is a further processed version of the file I got.
http://msdn.microsoft.com/en-us/library/system.windows.controls.spellcheck.aspx
I use Aspell-win32, it's old but it's open source, and works as well or better than the Word spell check. Came here looking for a built in solution.
I'm hoping people have some ideas to help solve this problem.
I am developing a C# ASP.NET website and the client requires an online form that users will fill in and submit. OK, so far so good.....
Imagine, say, a form that you fill in on paper - they normally have a distinctive look specific to the company and will be filed, quite possibly as a legally binding document.
I need to have an online form that when submitted emails the client with something they can print out and will look exactly like their printed forms.
As this is web based, I think the option of capturing a screenshot are out the question, so I'm wondering how best to approach this?
Even if I just had a form that captures the data presented how I want, how could I translate this data into the view they want?
Any ideas and suggestions greatly appreciated.
You'll need to take the raw data that was submitted and import it into a standard document (likely PDF). You can use Crystal or another reporting solution, or direct to PDF using one of the many PDF .NET solutions that are out there.
I don't think you'd even want to deal with making the document physically match the screen - much easier to make the web look like the web, and make the printed doc look like a printed doc.
Print a page (this one) from a Browser, notice all the headers and footers?
If you want serious control over how it is going to look, you will need to generate a PDF (or maybe XPS).
Couldn't you just use a sepparate page with a CSS that gives the desired look & feel?