Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing CDO with Outlook Object Model 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I'm having difficulty getting my head round replacing CDO 1.2.1 with Outlook Object Model.

I normally use the following code to attach inline files to emails
Code:
  ' *** POSITION CRITICAL *** you must dereference the
  ' attachment objects before changing their properties
  ' via CDO
  Set colAttach = Nothing
  Set l_Attach = Nothing
    
  ' initialize CDO session

  Set oSession = CreateObject("MAPI.Session")
  oSession.Logon "", "", True, False
  
  ' get the message created earlier
  Set oMsg = oSession.GetMessage(strEntryID)
  ' set properties of the attached graphic that make
  ' it embedded and give it an ID for use in an <IMG> tag
  

  
 'CSS File
  Set oAttachs = oMsg.Attachments
  Set oAttach = oAttachs.Item(1)
  Set colFields = oAttach.Fields
  Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "text/css")
  Set oField = colFields.Add(&H3712001E, "IMN")
  oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, True
  oMsg.Update

I don't seem to be able to find any examples of code that replaces this method.

Can anyone help?

Thanks,
1DMF.


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
I've found this...
Code:
Sub EmbeddedHTMLGraphicDemo()
' Outlook objects
Dim oApp as Outlook.Application
Dim oMsg As Outlook.MailItem
Dim colAttach As Outlook.Attachments
Dim oAttach As Outlook.Attachment
Dim oPA As Outlook.PropertyAccessor

' not an URL, a DASL property tag string
Const PR_ATTACH_MIME_TAG =

Const PR_ATTACH_CONTENT_ID = "urn:schemas:mailheader:content-id"

' not an URL, a DASL property tag string
Const PR_HIDE_ATTACH = _

On Error Resume Next

' create new Outlook MailItem
' Use CreateObject for Outlook.Application if not in OL VBA
Set oApp = Application
Set oMsg = oApp.CreateItem(olMailItem)
' add graphic as attachment to Outlook message
' change path to graphic as needed
Set colAttach = oMsg.Attachments
Set oAttach = colAttach.Add("c:\test\graphic.jpg")
oMsg.Save

' *** POSITION CRITICAL *** you must dereference the
' attachment objects before changing their properties
Set colAttach = Nothing
Set oAttach = Nothing

' set properties of the attached graphic that make
' it embedded and give it an ID for use in an <IMG> tag
Set colAttach = oMsg.Attachments
Set oAttach = colAttach.Item(1)
Set oPA = oAttach.PropertyAccessor
oPA.SetProperty PR_ATTACH_MIME_TAG, "image/jpeg"
oPA.SetProperty PR_ATTACH_CONTENT_ID,  "myident"
Set oPA = Nothing

Set oPA = oMsg.PropertyAccessor
oPA.SetProperty PR_HIDE_ATTACH, True
oMsg.Save

oMsg.HTMLBody = "<IMG align=baseline border=0 hspace=0 src=cid:myident>"
oMsg.Close olSave
oMsg.Display

' clean up objects
Set colAttach = Nothing
Set oAttach = Nothing
Set oPA = Nothing
Set oMsg = Nothing
Set oApp = Nothing
End Sub
but it seems to use Attachment.PropertyAccessor , which as i understand it is only available in Outlook 2007 onwards.

Am i correct in thinking that it is impossible to use outlook object model to attach inline attachments in this manner in office 2003 and CDO must be used, but it's imposible to use CDO in Outlook 2010 as it won't install?


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
it's imposible to use CDO in Outlook 2010 as it won't install?
Really ?
Even when you install CDO first, before Office 2010 ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yeah, i know about installing CDO first, I even posted a thread explaining that, but that's not the point.

I have a machine already with MSO2010 on and i'm not going to unistall it just to get round this issue.

I need (I am) rewritting the main DB with an EmailWrapper class but it seems 2003 & 2010 use different methods neither of which are compatible with each other [hairpull3]

I'm going to see if i can write it to you wich ever one is available





"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
grr, the amount of spam post on other threads trying to sell that redemption plugin is rediculous, you on commission stongm?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
What? Redemption is a life saviour. I've been using it for 8 or 9 years and it works extraordinarly well, ensuring functionality that Microsft decided to hide from VB and VBA programmers was available. The RDO library included, for example, is basically just a drop-in replacement for CDO 1.2.1 with the advantage that it now works in a 64bit environment

I'm not trying to sell you anything. The developer version is 100% completely free. No nag screens (except on initial installation). Has it occurred to you that the reason you keep seeing Redemption being offered as a solution is because it actually is the solution?

(there used to be at least one competitor to Redemption - the name of which escapes me - but it was a) nowhere near as good b) nowhere near as cheap. So, frankly, Redemption is about the only way you are going to achieve this through VB/VVBA

Your only other option is to interface directly with Extended MAPI (which is what Redemption ultimately wraps and gives VB access to). This predates .NET, so the currently is no official way to talk to it from any of the .NET languages, and the only way to do it is to write your code in C++. Have fun.
 
i did see the developer verion was free, but then it says to use in commercial environment was $300+

I'm writing in house code in a commercial environment, so assume developer version isn't valid for my purpose?

Have i miss read something or is their definition of 'commercial' different to mine?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
> is their definition of 'commercial' different to mine?

Nope - but you can download the developer version and play with it as much as you want to see if it helps/works without paying a cent.

Then you can judge for yourself it is worth $199.99 (not $300 - unless you want OutlookSpy)

And if not then you can always learn C++ instead!
 
It's still £100.00+ i don't have :-(

And if not then you can always learn C++ instead!
Yeah right, like that'll ever happen! [lol]

Well I've rewritten the DB so all email functions use a new EmailWrapper class.

I must admit there is bodged emailing code scattered all over the place, some real ugly legacy code lurks through out the DB!

At least now it all uses the one class object, which at any time I can alter to use Outlook Object Model & .PropertyAccessor , so migration *should* be a doddle!

Normal emails always did use the OOM , it's only when you want to attach inline mime files such as images and CSS that the CDO/MAPI was used!

And yes we have always had that pesky OOM security warning problem, but it's easily remedied using a simple little program called 'Express Click Yes'.

I'm so glad i sent myself to college and learned OO programming, it's making my life so much easier!

Though i'm still a total noob, so i'm sure i'll create some 'class soup' before I become proficient at it!







"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Thanks strongm for your help in all this, I've put an FAQ together to help others... faq705-7446


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top