Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Embed programatically created jpeg into HTML email?

Thread Tools

Embed programatically created jpeg into HTML email?

Posts: n/a
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,


Dim mSmtpClient As New SmtpClient()
If Left(SharedFunctions.fGetConnectionString, Len("Data
Source=MyConnection")) = "Data Source=MyConnection" Then
mSmtpClient.Host = ""
Dim SMTPUserInfo As New NetworkCredential("me",
mSmtpClient.Credentials = SMTPUserInfo
mSmtpClient.Port = 587
mSmtpClient.Host = ""
End If
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"

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

<script runat="server">

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

Response.ContentType = "image/jpeg"
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

' 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.

' Send the output to the client.
End Sub


<form id="form1" runat="server">

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to embed JNLP file into HTML page ? L Ng Java 1 12-02-2012 10:08 PM
Embed ".html" file into ".aspx" file yukijocelyn ASP .Net 0 08-06-2007 08:41 AM
Looking to embed python into html like mason Steven W. Orr Python 2 06-21-2007 02:31 PM
Embed an html page into a placeholder? John ASP .Net 2 03-02-2004 12:10 PM
How to embed dynamic generated image into HTML? Olav Tollefsen ASP .Net 2 03-01-2004 03:14 PM