Solved

Email Image from Byte Array

Posted on 2010-08-19
3
440 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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