Trouble attaching file to email using MAPI control 
Author Message
 Trouble attaching file to email using MAPI control

I'm writing an error logger component for an application that I want to be
able to send an error log file to our developers. I'm using the MAPI control
for this (VB6 SP3, Win2000 RC1)

I can get it to send an email message correctly but am having trouble
attaching the log file to the document. My code for sending looks like:

Private Sub cmdSend_Click()
On Error GoTo errhandler
Dim fso As Scripting.FileSystemObject

    Set fso = New Scripting.FileSystemObject

        If fso.FileExists(g_logFile) Then
            With MAPIMessages1
                .RecipDisplayName = txtRecip.Text
                .ResolveName
                .MsgSubject = "Error Report"

                .AttachmentIndex = 0
                .AttachmentType = mapData
                .AttachmentPathName = g_logFile
                .AttachmentName = "Error Report"
                .AttachmentPosition = 0
                .MsgReceiptRequested = True
                .send
            End With

        Else
            MsgBox "No Error Log to Send", vbApplicationModal +
vbExclamation

        End If

    End Select

    Me.Hide

errhandler:
End sub

If I comment out the Attchemnt code the lessage gets sent without trouble.
Without it commented I get an "Unspecified Error" from the MAPI control when
the send method is invoked.

Am I doing something wrong here? The log file exists and the specified path
is correct.

Thanks,

Don Kackman



Sun, 27 Jan 2002 03:00:00 GMT  
 Trouble attaching file to email using MAPI control
Donald,

Try making sure you have some type of message text, at least a few spaces.
An error can occur if the AttachmentPosition is invalid because it
represents a position with the existing message text.  If there is no
message text specified, the AttachmentPosition may not be considered valid,
even though it's zero.

For example, you might want to try the following in your app:

.MsgNoteText = Space$(2)
.AttachmentPosition = Len(.MsgNoteText) - 1

Hope this helps,

--
Vinnie Murdico
Software with Brains, Inc.
Visual Basic Controls and Components
SWBTracker - Value-Priced Defect Management Software
http://www.softwarewithbrains.com



Sun, 27 Jan 2002 03:00:00 GMT  
 Trouble attaching file to email using MAPI control
That solved the problem. Thanks for the quick reply.

don


Quote:
> Donald,

> Try making sure you have some type of message text, at least a few spaces.
> An error can occur if the AttachmentPosition is invalid because it
> represents a position with the existing message text.  If there is no
> message text specified, the AttachmentPosition may not be considered
valid,
> even though it's zero.

> For example, you might want to try the following in your app:

> .MsgNoteText = Space$(2)
> .AttachmentPosition = Len(.MsgNoteText) - 1

> Hope this helps,

> --
> Vinnie Murdico
> Software with Brains, Inc.
> Visual Basic Controls and Components
> SWBTracker - Value-Priced Defect Management Software
> http://www.softwarewithbrains.com



Sun, 27 Jan 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. trouble attaching file with MAPI control

2. Attaching files using MAPI controls

3. Attaching files via MAPI-control

4. script which send an email to an email adress, with file attached

5. Using Mapi email Control Question

6. Sending email using MAPI controls

7. Using MAPI Controls to send Email???

8. eMail-Attachments using MAPI-Control

9. HTML format when sending email using MAPI Control

10. Email Software in VB using APIs, ie., without using MAPI object

11. Attaching a File Using the Winsock Control

12. MAPI, Outlook and Attached file name

 

 
Powered by phpBB® Forum Software