Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mapi vs Outlook (VB6)

    With my project, I am using the VB Mapi controls with very good results.
    Using these controls with Outlook Express is fine but Outlook causes a problem.
    On some Outlook versions, the application is quite happy but, withsome versions it is not.

    Error 32002 seems to be most popular which I can over ride with earlier versions but later 2002 Version I can't.

    Is there another method of sending mails with multiple attachments which doesn't rely heavily on using the default mail program ?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Mapi vs Outlook (VB6)

    Can you see a pettern when this error is raised? The Knowledge Base mentions a few circumstances in which it can occur:
    - You add an attachment but the body of the message is empty (solution: set it to a space)
    - You add multiple attachments and specify the same AttachmentPosition for each, or don't specify the AttachmentPosition, which amounts to the same (solution: specify a different position for each attachment)
    - You send a message to multiple recipients without resolving each recipient (solution: call the ResolveName method of the MAIPIMessage after adding a recipient.)

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mapi vs Outlook (VB6)

    - You add multiple attachments and specify the same AttachmentPosition for each, or don't specify the AttachmentPosition, which amounts to the same (solution: specify a different position for each attachment)

    Hans
    I have a feeling that this may be causing the error.
    I tested this morning and one attachment was ok, when I added multiple attachments, the error occured.
    Checking the code, we attend to the index positions anyway so I'm confused on how the error can occur:

    <pre> For i = 0 To Me.lstDocs.ListCount - 1
    If lstDocs.Selected(i) Then
    .AttachmentIndex = i
    .AttachmentPosition = i
    .AttachmentPathName = strPath & Me.lstDocs.List(i)

    WriteLog GetComputerName & " " & GetNetUser & _
    " Mail Sent " & " " & Me.lstDocs.List(i)
    End If
    Next i

    .Send True</pre>


    Somethings niggling at me with the .Send <font color=blue>True</font color=blue>

    ?????????

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Mapi vs Outlook (VB6)

    The AttachmentPosition is handled correctly, assuming that the length of the body of the e-mail is large enough to accomodate all attachments (it must contain at least as many characters as there are attachments.)

    The argument of the Send method of the MAPIMessages control is True to display a dialog in which the user can specify the recipient etc., False to send the message without user intervention; in the latter case, an error will occur if not all required information has been filled in.

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Mapi vs Outlook (VB6)

    Dave,
    [Edited from previous babblings about attachmentposition by mistake - sorry about that!]
    It seems to me that your i counter can be higher than the permissible attachmentindex value - i.e. it can be higher than the actual number of attachments.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mapi vs Outlook (VB6)

    Rory

    ?? I don't understand what you mean, can you clarify ??

  7. #7
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Mapi vs Outlook (VB6)

    I'm assuming from your code that you have a listbox from which the user can pick files to attach.
    Let's say your user picks file 1 and 3. The relevant values for i will be 0 and 2. The first attachment will have an index of 0 and the second of 1 but you are referring to 2. As it happens, I've just been doing some quick testing on OL2002 and I'm not sure that is your problem as I cannot get even a simple message to actually send. I will dig some more and see if I can work out why (may be the security 'improvements').
    Regards,
    Rory

    Microsoft MVP - Excel

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Mapi vs Outlook (VB6)

    The loop index i will increase for every item in the list box, but not all items will be selected, so using i as AttachmentIndex will create gaps in the sequence. This is not allowed. (It doesn't matter for the AttachmentPosition). Try using a separate index for the AttachmentIndex:
    <pre> Dim lngAttIndex As Long
    lngAttIndex = 0
    For i = 0 To Me.lstDocs.ListCount - 1
    If lstDocs.Selected(i) Then
    ' Assign index
    .AttachmentIndex = lngAttIndex
    .AttachmentPosition = lngAttIndex
    ' Increase index for next one
    lngAttIndex = lngAttIndex + 1
    .AttachmentPathName = strPath & Me.lstDocs.List(i)

    WriteLog GetComputerName & " " & GetNetUser & _
    " Mail Sent " & " " & Me.lstDocs.List(i)
    End If
    Next i

    Send True</pre>

    This will ensure that the AttachmentIndex increases by 1.

  9. #9
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Mapi vs Outlook (VB6)

    Hans has answered much more clearly than I did! (Thanks, Hans). I got the basic code to run and by hardcoding an incorrect attachmentindex I got error 32011. 32002 appears if I do not use Send True to allow the user to confirm. I can only assume that this is a security thing.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mapi vs Outlook (VB6)

    Thankyou Hans.
    I will incorporate the code accordingly.
    Rory's explanation (next post) makes sense to me now.

  11. #11
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mapi vs Outlook (VB6)

    Rory

    I read somewhere that pre OL2002 there was setting in Tools|Options|Security : Warn me other programs try to send mails other than me !

    But I think that's now gone post OL2002

    So if it's not the attachment position/Index, could this be another area to cover ?

  12. #12
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Mapi vs Outlook (VB6)

    Dave,
    When I sorted out the attachmentindex issue and used Send True, everything worked OK (as long as you say yes to the security dialog), although you don't seem to be able to put attachmentposition = -1 which I thought I had read you could.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  13. #13
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mapi vs Outlook (VB6)

    Rory

    I've set up Outlook on my laptop and created a fresh EXE with Hans modified code.
    On a single attachment i works fine.
    With more than one attachment, when we reach the .Send True line, here's where we bomb out and cause the 32002 error.

    Stepping thru F8 line by line checking the indexing alls ok until that line ?

  14. #14
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mapi vs Outlook (VB6)

    OK, I've found out why the fault occurs and tested it to be true.

    The .MsgNoteText needs to use the underlying "Space(?) value as place holders for the attachments.
    Mine is currently set to 2, so will allow me to attach only 2 files.
    If I increment the value, I can attach the same amount of files, So :
    If Space(4), then I can attach 4 or less files but no more than that.
    So here's the question.

    How can we programatically increment this value to equal the attachment position (from Hans's code ".lngAttIndex")

  15. #15
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Mapi vs Outlook (VB6)

    Does this work for you:
    <pre>Private Sub Command1_Click()
    'Logon & Sync
    MAPISession1.SignOn
    Debug.Print MAPISession1.UserName
    'Create Message w/Attachments then Send
    With MAPIMessages1
    .SessionID = MAPISession1.SessionID
    .Compose
    .MsgSubject = "OCX - Test Message"
    .RecipDisplayName = "Rory Archibald"
    ' .ResolveName

    'The value 2 is passed to the Space() function in the
    'next line because there are two attachments to add.
    'These spaces act as placeholders for the attachments.
    .MsgNoteText = _
    Space(2) & vbCrLf & _
    "This message was sent from the MSMAPI32.OCX." & vbCrLf & _
    "This message contains 2 attachments."

    'Replace the AttachmentPathName values below as applicable...
    .AttachmentIndex = 0
    .AttachmentPosition = 0
    .AttachmentPathName = ("c:test1.txt")
    .AttachmentIndex = 1
    .AttachmentPosition = 1
    .AttachmentPathName = ("c:test2.txt")
    .Send True
    End With

    MAPISession1.SignOff


    End Sub
    </pre>

    You will need a commandbutton on your form (or however you choose to run it) and the 2 text files on your c drive to test.
    If that works then it appears Outlook is not the issue; if not then what Service Packs dd you have installed?
    Regards,
    Rory

    Microsoft MVP - Excel

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •