MS Office Forum / Outlook / Programming Forms / February 2004
Mapi Object and attachments
|
|
Thread rating:  |
Gabriel - 18 Feb 2004 13:07 GMT 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
Sue Mosher [MVP-Outlook] - 18 Feb 2004 13:21 GMT Where is this code running? I don't see that you're instantiating Item anywhere.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
> 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 [quoted text clipped - 35 lines] > > Thanks in advance Gabriel Gramajo - 18 Feb 2004 14:55 GMT 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
Sue Mosher [MVP-Outlook] - 18 Feb 2004 15:11 GMT 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.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
> This is the completely Source: > [quoted text clipped - 59 lines] > Set oSession = Nothing > End Function Gabriel Gramajo - 18 Feb 2004 16:35 GMT 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 [quoted text clipped - 57 lines] > Set oSession = Nothing > End Function It?s a vba code.
Thanks in advance
Sue Mosher [MVP-Outlook] - 18 Feb 2004 16:51 GMT I still don't understand where this code is running or whether you are forwarding or replying programmatically or manually.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
> Well, here?s the thread: > >Someone can tell which i?m doing wrong with this code. It >works great [quoted text clipped - 69 lines] > > Thanks in advance Gabriel Gramajo - 18 Feb 2004 17:55 GMT 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.
> Well, here?s the thread: > >Someone can tell which i?m doing wrong with this code. It >works great [quoted text clipped - 69 lines] > > Thanks in advance Sue Mosher [MVP-Outlook] - 18 Feb 2004 18:17 GMT 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.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
> 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 [quoted text clipped - 80 lines] > > > > Thanks in advance Gabriel Gramajo - 18 Feb 2004 19:40 GMT 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.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
> 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 [quoted text clipped - 80 lines] > > > > Thanks in advance Sue Mosher [MVP-Outlook] - 18 Feb 2004 20:00 GMT 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.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
> One final question how can i enforce using the default form in Reply , > Reply to All and forward. [quoted text clipped - 114 lines] > > > > > > Thanks in advance
|
|
|