-
Feb 12th, 2004, 12:44 AM
#1
VB - Embedd an image into an Outlook email message body
Instead of adding an image to the body of a message with a web
link (img scr='http://somewhere.com'). This code will show how to
embedd the image like when you click on Insert > Picture...
VB Code:
Option Explicit
'Add reference to MS Outlook x.x Object Library
'Picture to be added as an attachment and modified src location for each embedded picture.
Private Sub Command1_Click()
Dim oApp As Outlook.Application
Dim oEmail As MailItem
Dim colAttach As Outlook.Attachments
Dim oAttach As Outlook.Attachment
'create new Outlook MailItem
Set oApp = CreateObject("Outlook.Application")
Set oEmail = oApp.CreateItem(olMailItem)
'add graphic as attachment to Outlook message
'change path to graphic as needed
Set colAttach = oEmail.Attachments
Set oAttach = colAttach.Add("D:\my documents\[color=red]MyPic.jpg[/color]")
oEmail.Close olSave
'change the src property to 'cid:your picture filename'
'it will be changed to the correct cid when its sent.
oEmail.HTMLBody = "<BODY><FONT face=Arial color=#000080 size=2></FONT>" & _
"<IMG alt='' hspace=0 src='[color=red]cid:MyPic.jpg[/color]' align=baseline border=0> </BODY>"
oEmail.Save
oEmail.Display 'fill in the To, Subject, and Send. Or program it in.
Set oEmail = Nothing
Set colAttach = Nothing
Set oAttach = Nothing
Set oApp = Nothing
End Sub
When the message is displayed it will look like
its not embedded correctly, but when Outlook sends the
message it will embedd it and link the proper source cid.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Aug 30th, 2008, 11:40 PM
#2
Fanatic Member
Re: VB - Embedd an image into an Outlook email message body
thanks man. a simple Qs. why do i need to save the oEmail?
one thing more, when i removed the attached image and send the images not also showing.
the code work but its kinda odd to attach the image(company logo at complimentary clause) for every mail created?
Last edited by jlbantang; Aug 31st, 2008 at 12:07 AM.
-
Jul 10th, 2009, 10:05 PM
#3
New Member
Re: VB - Embedd an image into an Outlook email message body
How to send picture into new message while Outlook is opening ?
Tell me about do it ?
Thanks !
-
Mar 27th, 2011, 04:01 AM
#4
Member
Re: VB - Embedd an image into an Outlook email message body
Hey i tried this code but i am not getting my image embedded in the body of email. Can u tel me why please. Here is the code:
Dim oApp As Outlook.Application
Dim oEmail As MailItem
Dim colAttach As Outlook.Attachments
Dim oAttach As Outlook.Attachment
'create new Outlook MailItem
Set oApp = CreateObject("Outlook.Application")
Set oEmail = oApp.CreateItem(olMailItem)
'add graphic as attachment to Outlook message
'change path to graphic as needed
Set colAttach = oEmail.Attachments
'Set oAttach = colAttach.Add("D:\my documents\MyPic.jpg")
Set oAttach = colAttach.Add("C:\TITAN\imagefile.jpeg")
'change the src property to 'cid:your picture filename'
'it will be changed to the correct cid when its sent.
With oEmail
.To = "anselseenu2888@gmail.com"
.Subject = "TITAN DAILY REPORT"
'.Body = "Please find the TITAN daily report pie chart"& vbNewLine& "C:\TITAN\imagefile.jpeg"
'.Body = "Please find the pie chart"
.HTMLBody = "<BODY><FONT face=Arial color=#000080 size=2></FONT>" & _
"<IMG alt='' hspace=0 src='cid:C:\TITAN\imagefile.jpeg' align=baseline border=0> </BODY>"
oEmail.Save
oEmail.Display 'fill in the To, Subject, and Send. Or program it in.
'.Attachments.Add "\\server\drive\folder\filename", olByValue, 1
.Send
End With
'oEmail.Close olSave
MsgBox "Email sent"
Set oEmail = Nothing
Set colAttach = Nothing
Set oAttach = Nothing
Set oApp = Nothing
End Sub
-
Mar 27th, 2011, 10:54 AM
#5
Re: VB - Embedd an image into an Outlook email message body
In your related thread in the Classic VB section, see if one of the issues regarding how you are creating the jpg file is the cause.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|