Feb 7, 2011

C# & Outlook: Insert image in email body

Haven't posted in a while...I blame it on being lazy. Which is not a bad thing, I always maintain a lazy IT guy is a damn effective IT guy. But I'm veering off topic now.

Figured something out today that might be useful. As you may know there are a few ways of sending mail with your C# app. You can use straight SMTP or you can integrate with various other email clients. The nice feature of the latter method being you'll have a record of the email in your Sent Items. By the way I use Outlook 2007 so for the purpose of this article. Setting up the basic integration is pretty easy so I'm gonna skip that - have a look at http://support.microsoft.com/kb/310262 for info on how it works. Make sure you use an HTML body type. My problem was getting an image (in my case, logo) into the body of the email. It turned out to be as easy as referencing an image in the file system in an img tag, for example:

<img src="" + Application.StartupPath + "\Images\logo.png" + "" align='baseline' border='0' />

Till next time, whenever that may be.

No comments: