Solved

Email Image from Byte Array

Posted on 2010-08-19
3
441 Views
Last Modified: 2013-11-27
Hi to all,

I have an SQL 2005 database where I store thumbnails of my Item images. I need to email these images to some users using an automated process. I can't save the byte array to file to add this image as an attachment because of our security policy.

I was wondering if there is a way to email this image as a byte array to the user and then the user will be able to see the picture. Any suggestions would be appreciated.

I am using Visual Studio 2010 with .Net 4.0

Thanks in advance.
0
Comment
Question by:ALawrence007
3 Comments
 
LVL 18

Accepted Solution

by:
Dennis Aries earned 250 total points
ID: 33475630
You can stuff your byte-array/image into a memorystream and use that to create the attachment
See http://www.systemnetmail.com/faq/3.4.2.aspx for an example.
Just make sure you set the correct MIME-type
0
 
LVL 8

Assisted Solution

by:bhmahler
bhmahler earned 250 total points
ID: 33477460
If you can use HTML emails then you can add the image as a base64 image.  However, many email clients may interpret this as spam.  To do it would be something like this
Dim imgBytes As Byte() = GetYourBytesFromDB()
Dim b64Image As String = Convert.ToBase64String(imgBytes)

'Make sure you specify the proper image type
Dim imgHtml As String = "<img src=""data:image/png;base64," & b64Image & """ />"

'Or for C#

byte[] imgBytes = getBytesFromDb();
string b64String = Convert.ToBase64String(imgBytes);

string imgHtml = "<img src=\"data:image/png;base64," & b64Image & "\" />";

Open in new window

0
 

Author Closing Comment

by:ALawrence007
ID: 33478632
Thanks Guys!! I will actually be using Both Solutions!!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question