Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Email JPG Image from In-Memory Image Data
This VB6 example program shows how to manually construct and send an HTML mail. The JPG image is loaded from in-memory data.
' VB source code to create a simple HTML email and send it.
' The image data is loaded from a file, and then added
' from memory. This technique can be used in cases where
' the image data is coming from a non-file source such
' as an image database.
' This example manually builds the HTML mail.
' The Chilkat MHT component can be used in conjunction with
' Chilkat Mail to automate the creation of HTML mail from
' HTML files or Web pages (URLs).
Private Sub Command1_Click()
' Create a mailman object for sending HTML email
Dim mailman As ChilkatMailMan2
Set mailman = New ChilkatMailMan2
mailman.UnlockComponent "30-day Trial"
' Set the SMTP host.
mailman.SmtpHost = "smtp.earthlink.net"
' Only set the username/password if the SMTP server requires it.
'mailman.SmtpUsername = "my_username"
'mailman.SmtpPassword = "my_password"
' Create the email, add content, address it, and sent it.
Dim email As ChilkatEmail2
Set email = New ChilkatEmail2
email.AddTo "Chilkat Support", "support@chilkatsoft.com"
email.Subject = "Here is an HTML e-mail with an image"
' CkData is part of the ChilkatUtil.dll
Dim imageData As New CkData
success = imageData.LoadFile("sample.jpg")
' Add the image to the HTML email. The name of the file embedded in the email
' will be "sprinter.jpg"
imageContentID = email.AddRelatedData(imageData.GetBinary(), "sprinter.jpg")
email.SetHtmlBody ("<!DOCTYPE HTML PUBLIC " & Chr(34) & _
"-//W3C//DTD HTML 4.0 Transitional//EN" & Chr(34) & _
"><HTML><HEAD></HEAD><BODY>" & _
"<br>This is an example of embedding an image in HTML email.<BR><IMG SRC=" & _
Chr(34) & "cid:" & imageContentID & Chr(34) & _
"><br>(The content ID of the image looks like this: " & _
imageContentID & "<br>The <b>HTML</b> for embedding the image looks like this: <img src=" & _
Chr(34) & "cid:" & imageContentID & Chr(34) & "><br></BODY></HTML>")
email.AddPlainTextAlternativeBody "This is the plain text"
email.From = "bigfoot@chilkatsoft.com"
'email.SendEncrypted = 1
' Call SendEmail to send HTML email.
success = mailman.SendEmail(email)
If (success = 1) Then
Label1.Caption = "Mail Sent!"
Else
Label1.Caption = "Errors occured. Check log.xml for information"
mailman.SaveLastError "log.xml"
End If
Set email = Nothing
Set mailman = Nothing
End Sub
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.