Mapi Object and attachments

G

Gabriel

Someone can tell which i´m doing wrong with this code. It works great
when i´m create a new mail with attachments but when i forward or
reply mails with files the first mail takes the fields attributes and
it´s lost and the company logo figures as an attach instead to be
embeded.


Function NuevoEnvio()
Dim oSession
Dim oMapiItem
Dim colAttachs
Dim oAttach
Dim colFields
Dim oField
Dim cantidad
Const CdoPR_ATTACH_MIME_TAG = &H370E001E
Set colAttachs = Item.Attachments
cantidad = colAttachs.count
colAttachs.Add("\\public\Imagenes\companylog.gif")
Item.Save 'create EntryID
Set colAttachs = Nothing 'dereference before using MAPI
set oSession = CreateObject("MAPI.Session")
oSession.Logon ,,false,false,0
Set oMapiItem = oSession.GetMessage(Item.EntryID)
Set colAttachs = oMapiItem.Attachments
Set oAttach = colAttachs(1)
'Set oAttach = colAttachs(cantidad)
Set colFields = oAttach.Fields
Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/gif")
Set oField = colFields.Add(&H3712001E, "myimage")
oMapiItem.Fields.Add "{0820060000000000C000000000000046}0x8514", 11,
True
oMapiItem.Update
oMapiItem.Send
Set oMapiItem = Nothing
oSession.Logoff
Set oSession = Nothing
End Function


Thanks in advance
 
S

Sue Mosher [MVP-Outlook]

Where is this code running? I don't see that you're instantiating Item
anywhere.
 
G

Gabriel Gramajo

This is the completely Source:

Function AlEnviar()
On Error Resume Next
Set objM = GetObject(,"Outlook.Application")
If Err.Number <> 0 then
Set objM = Application.CreateObject("Outlook.Application")
'MsgBox(Err.Number & "-" & Err.Description)
Err.Clear
End If

Set objMail = objM.ActiveInspector.CurrentItem

if instr(objMail.Subject, "Company -") <= 0 then
objMail.Subject = "Company - " & objMail.Subject
end if
objMail.HTMLBody = "<IMG align=baseline border=0 hspace=0
src=""cid:myimage"">" & objMail.HTMLBody

Call NuevoEnvio
Set objMail = Nothing
Set objAtt = Nothing
Set objM = Nothing
End Function

Function Item_Send()
Call AlEnviar
Item_Send = False
Set objInsp = Item.GetInspector
objInsp.Close 2 'olPromptForSave
End Function

Function NuevoEnvio()
Dim oSession
Dim oMapiItem
Dim colAttachs
Dim oAttach
Dim colFields
Dim oField
Dim cantidad
Const CdoPR_ATTACH_MIME_TAG = &H370E001E
Set colAttachs = Item.Attachments
cantidad = colAttachs.count
colAttachs.Add("\\SAMANNT\public\Imagenes\saman.gif")
Item.Save 'create EntryID
Set colAttachs = Nothing 'dereference before using MAPI
set oSession = CreateObject("MAPI.Session")
oSession.Logon ,,false,false,0
Set oMapiItem = oSession.GetMessage(Item.EntryID)
Set colAttachs = oMapiItem.Attachments
Set oAttach = colAttachs(1)
'Set oAttach = colAttachs(cantidad)
Set colFields = oAttach.Fields
Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/gif")
Set oField = colFields.Add(&H3712001E, "myimage")
oMapiItem.Fields.Add "{0820060000000000C000000000000046}0x8514", 11,
True
oMapiItem.Update
oMapiItem.Send
Set oMapiItem = Nothing
oSession.Logoff
Set oSession = Nothing
End Function
 
S

Sue Mosher [MVP-Outlook]

Source for what? Is this a script? VBA code? VBScript? What's the original
issue? The newsgroup interface you are using apparently does not quote
earlier messages in the thread, making your latest message so short on
detail that you risk not getting the answer you're looking for. Please take
the time to quote the original message.
 
G

Gabriel Gramajo

Well, here´s the thread:
Someone can tell which i´m doing wrong with this code. It >works great
when i´m create a new mail with attachments but when i >forward or
reply mails with files the first attached file takes the fields
attributes and
it´s lost and the company logo figures as an attach >instead to be
embeded.
Function AlEnviar()
On Error Resume Next
Set objM = GetObject(,"Outlook.Application")
If Err.Number <> 0 then
Set objM = Application.CreateObject("Outlook.Application")
'MsgBox(Err.Number & "-" & Err.Description)
Err.Clear
End If

Set objMail = objM.ActiveInspector.CurrentItem

if instr(objMail.Subject, "Company -") <= 0 then
objMail.Subject = "Company - " & objMail.Subject
end if
objMail.HTMLBody = "<IMG align=baseline border=0 hspace=0
src=""cid:myimage"">" & objMail.HTMLBody

Call NuevoEnvio
Set objMail = Nothing
Set objAtt = Nothing
Set objM = Nothing
End Function

Function Item_Send()
Call AlEnviar
Item_Send = False
Set objInsp = Item.GetInspector
objInsp.Close 2 'olPromptForSave
End Function

Function NuevoEnvio()
Dim oSession
Dim oMapiItem
Dim colAttachs
Dim oAttach
Dim colFields
Dim oField
Dim cantidad
Const CdoPR_ATTACH_MIME_TAG = &H370E001E
Set colAttachs = Item.Attachments
cantidad = colAttachs.count
colAttachs.Add("\\SAMANNT\public\Imagenes\saman.gif")
Item.Save 'create EntryID
Set colAttachs = Nothing 'dereference before using MAPI
set oSession = CreateObject("MAPI.Session")
oSession.Logon ,,false,false,0
Set oMapiItem = oSession.GetMessage(Item.EntryID)
Set colAttachs = oMapiItem.Attachments
Set oAttach = colAttachs(1)
'Set oAttach = colAttachs(cantidad)
Set colFields = oAttach.Fields
Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/gif")
Set oField = colFields.Add(&H3712001E, "myimage")
oMapiItem.Fields.Add "{0820060000000000C000000000000046}0x8514", 11,
True
oMapiItem.Update
oMapiItem.Send
Set oMapiItem = Nothing
oSession.Logoff
Set oSession = Nothing
End Function

It´s a vba code.

Thanks in advance
 
S

Sue Mosher [MVP-Outlook]

I still don't understand where this code is running or whether you are
forwarding or replying programmatically or manually.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Gabriel Gramajo

I put the past code into a form in Outlook 2000. I´m set that form as
default by registry to enforce sending the company image logo embeded
into the hmtl code of all outing mails.

I hope you understand this at all.

Thanks in advance.

G.G.
 
S

Sue Mosher [MVP-Outlook]

You might want to start by cleaning up the code. There is no need to use
GetObject or CreateObject, since VBScript code behind a form supports an
intrinsic Application object. Use that object everywhere you now have objM.

Similarly, the item where the code is running is the intrinsic Item object.
You should be using that object instead of ActiveInspector.CurrentItem.

You should not need to close the inspector in your Item_Send event handler.
Outlook closes the outgoing item automatically.

Also, on the (Actions) page for the custom form, try setting the Reply,
Reply to All, and Forward actions to explicitly use the custom published
form.

Finally, if all the above doesn't fix it, it might be useful to add a MsgBox
statement to the Item_Open event handler to find out if any code is running
at all. If it is, try taking out your On Error statements and/or stepping
through your procedures with the script debugger to see if errors are
occurring.
 
G

Gabriel Gramajo

One final question how can i enforce using the default form in Reply ,
Reply to All and forward.

Thanks for your time and help,

Gabriel.


---
You might want to start by cleaning up the code. There is no need to use
GetObject or CreateObject, since VBScript code behind a form supports an
intrinsic Application object. Use that object everywhere you now have
objM.

Similarly, the item where the code is running is the intrinsic Item
object.
You should be using that object instead of ActiveInspector.CurrentItem.

You should not need to close the inspector in your Item_Send event
handler.
Outlook closes the outgoing item automatically.

Also, on the (Actions) page for the custom form, try setting the Reply,
Reply to All, and Forward actions to explicitly use the custom published
form.

Finally, if all the above doesn't fix it, it might be useful to add a
MsgBox
statement to the Item_Open event handler to find out if any code is
running
at all. If it is, try taking out your On Error statements and/or
stepping
through your procedures with the script debugger to see if errors are
occurring.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

If you've use the registry substitution method to make a publish form the
compose default, it will apply to all new messages, including replies and
forwards. If you're seeing different behavior, post your Outlook version.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top