473,418 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Embed programatically created jpeg into HTML email?

I have two pieces of VB.NET code below:

a) Sends an email
b) Returns a programmatically created jpeg image to a webpage.

How can I embed the programmatically created jpeg into an HTML formatted
email (without saving the jpeg to disk)?

Code a)
======

Imports Microsoft.VisualBasic
Imports System.Net.Mail
Imports System.Net

Public Class sfSendMail

Shared Function fSendMail( _
ByVal strTo As String, _
ByVal strFrom As String, _
ByVal strSubject As String, _
ByVal strBody As String, _
Optional ByVal strCC As String = "", _
Optional ByVal strBCC As String = "", _
Optional ByVal strBodyHTML As String = "") As String

fSendMail = ""

'Send mail
Dim mMailMessage As New MailMessage()
Dim strMediaType As String
Dim avPlainText As AlternateView
Dim avHTMLContent As AlternateView

mMailMessage.From = New MailAddress(strFrom)
mMailMessage.To.Add(New MailAddress(strTo))

If strBCC <"" Then
mMailMessage.Bcc.Add(New MailAddress(strBCC))
End If

If strCC <"" Then
mMailMessage.CC.Add(New MailAddress(strCC))
End If

mMailMessage.Subject = strSubject

strMediaType = "text/plain"
avPlainText = AlternateView.CreateAlternateViewFromString(strBod y,
Nothing, strMediaType)

strMediaType = "text/html"
avHTMLContent =
AlternateView.CreateAlternateViewFromString(strBod yHTML, Nothing,
strMediaType)

mMailMessage.AlternateViews.Add(avPlainText)
mMailMessage.AlternateViews.Add(avHTMLContent)
Try
Dim mSmtpClient As New SmtpClient()
If Left(SharedFunctions.fGetConnectionString, Len("Data
Source=MyConnection")) = "Data Source=MyConnection" Then
mSmtpClient.Host = "smtp.site1.com"
Dim SMTPUserInfo As New NetworkCredential("me",
"mypassword")
mSmtpClient.Credentials = SMTPUserInfo
mSmtpClient.Port = 587
Else
mSmtpClient.Host = "site2.com"
End If
mSmtpClient.Send(mMailMessage)
fSendMail = "True"
Catch exc As Exception
fSendMail = "Email send failure: " + exc.ToString()
End Try

End Function
End Class
Code b)
======

<%@ Page Language="VB" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<%@ import Namespace="System.Drawing.Drawing2D" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head id="Head1" runat="server" />

<script runat="server">

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Response.ContentType = "image/jpeg"
Response.Clear()
Response.BufferOutput = True

' Create a font style.
Dim rectangleFont10 As New Font("Arial", 10, FontStyle.Bold)
Dim rectangleFont32 As New Font("Arial", 32, FontStyle.Bold)
Dim rectangleFont7 As New Font("Arial", 7, FontStyle.Bold)

' Create integer variables.
Dim height As Integer = 150
Dim width As Integer = 150

' Create a bitmap and use it to create a graphics object.
Dim bmp As New Bitmap(width, height, PixelFormat.Format24bppRgb)
Dim g As Graphics = Graphics.FromImage(bmp)

g.SmoothingMode = SmoothingMode.AntiAlias
g.Clear(Color.LightGray)
' Use the Graphics object to draw three rectangles.
g.DrawRectangle(Pens.White, 1, 1, width - 3, height - 3)
g.DrawString("My Text 1", rectangleFont7, SystemBrushes.WindowText,
New PointF(5, 15))
g.DrawString("My Text 2", rectangleFont32, SystemBrushes.WindowText,
New PointF(40, 35))
g.DrawString("My Text 3", rectangleFont10, SystemBrushes.WindowText,
New PointF(40, 90))
g.DrawString("My Text 4", rectangleFont7, SystemBrushes.WindowText,
New PointF(35, 125))
' Save the bitmap to the response stream and
' convert it to JPEG format.
bmp.Save(Response.OutputStream, ImageFormat.Jpeg)

' Release memory used by the Graphics object and the bitmap.
g.Dispose()
bmp.Dispose()

' Send the output to the client.
Response.Flush()
End Sub

</script>

<body>
<form id="form1" runat="server">
</form>
</body>
</html>
Sep 2 '08 #1
0 1701

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: AES/newspost | last post by:
Can anyone provide a quick tip on the html structure to link from a thumb to a movie poster and from there on to a QuickTime movie, all in one go, using EMBED? I have a number of (large)...
2
by: John | last post by:
Hi, heres a brief description of what I'm trying to do. I have a sql table named colors that looks like this: color_id color_name 1 blue 2 red 3......... and so...
2
by: Olav Tollefsen | last post by:
I have som code that dynamically generates an image and writes it back to the browser from an .aspx codebehind file like this: System.Drawing.Image image; image = GenerateImage();...
24
by: Manuel | last post by:
Is it possible to embed an image, like a company logo in a CDOSYS generated message? If yes, I´ll apreciate some code sample. I´ve been able to format messages in html the way I like, but I...
3
by: abrtlt | last post by:
I would like to have a web page in which, when the user clicks on any of several specific elements, a specific audio file is played, without reloading the page. The specific audio file name is...
8
by: CodeLeon | last post by:
Hi, All. I am creating a setup program. The way it works is that the user creates their setup info, my program generates the C# code for a setup executable, embeds the xml file containing the info...
4
by: csgraham74 | last post by:
Ok - i was wondering if someone could help me. im basically trying to embed an html string in piece of XML. i created an xsl and added the CDATA into the xml around the html i wish to render....
11
by: Mark B | last post by:
I want to display a pre-designed graphical 'performance badge' on certain webpages (round, about 2cm diameter) next to a salesperson's details. I have a function,...
2
by: premMS143 | last post by:
Hello Everybody, Here i'm facing one problem with VB6.0. I've prepared a project related to Computer Institution. Here, Everything is working fine. But now I want to add one new thing. The...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.