?
Solved

MAPISendMail giving error 11 (Attachment not found)

Posted on 2001-07-13
4
Medium Priority
?
2,416 Views
Last Modified: 2012-05-04
I am trying to send an email using the following code:

Private Sub SendMailx(Address As String, _
                      Subject As String, _
                      Body As String, _
                      FilePath As String)
 Dim suc As Long
 Dim SesID As Long
 Dim Msg As MapiMessage
 Dim Recips(0) As MapiRecip
 Dim Attach(0) As MAPIfile
   
    suc = MAPIResolveName(0, 0, Address, 0, 0, Recips(0))
    If suc <> SUCCESS_SUCCESS Then
        MsgBox "Recipient not found..."
    End If
   
    With Msg
        .Reserved = 0
        .Subject = Subject
        .NoteText = Body
        .MessageType = vbNullString
        .DateReceived = vbNullString
        .ConversationID = vbNullString
        .Flags = 0
        .RecipCount = 1
        .FileCount = 1
    End With
   
    With Attach(0)
        .Reserved = 0
        .Flags = MAPI_OLE_STATIC
        .PathName = FilePath
        .FileName = "test.txt"
        .FileType = "Text File"
    End With
   
    suc = MAPISendMail(0, 0, Msg, Recips(0), _
          Attach(0), 0, 0)
    If suc <> SUCCESS_SUCCESS Then
        MsgBox "Unable to send Mail:" + Format(suc)
    End If
End Sub

I Call this sub like this:
SendMailx "v-riaanm@microsoft.com", "testing123", _  
   "please find the file attatched", "c:\test.txt"

Now I checked about 100 times that c:\test.txt exists, but when calling MAPISendMail I get the return code:11 (MAPI_E_ATTACHMENT_NOT_FOUND)

Could someone please help me solve this?
0
Comment
Question by:SADiver
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:SADiver
ID: 6280141
By the way,
I am using the MAPI Declarations of the "MAPI32.dll"
0
 

Expert Comment

by:surki
ID: 6280197
http://www.freevbcode.com/ShowCode.Asp?ID=773

Try this:
Public Function send_mail(sendto As String, subject As String, _
 text As String) As Boolean

'Add The MAPI Components and
'add a MAPI Session and MAPI mail control to your form

On Error GoTo ErrHandler
   With MAPISession1
           .DownLoadMail = False
           .LogonUI = True
           .SignOn
           .NewSession = True
           MAPIMessages1.SessionID = .SessionID
   End With
   With MAPIMessages1
       .Compose
       .RecipAddress = sendto
       .AddressResolveUI = True
       .ResolveName
       .MsgSubject = subject
       .MsgNoteText = text
       .Send False
   End With
sendmail = True
ErrHandler:
 End Function

0
 

Author Comment

by:SADiver
ID: 6280208
I dont want to use the MAPI Controls, surki.
0
 
LVL 20

Accepted Solution

by:
hes earned 200 total points
ID: 6280734
Try this:

With Attach(0)
       .Reserved = 0
       ' .Flags = MAPI_OLE_STATIC comment out
       .PathName = "c:\test.txt"
       ' .FileName = "test.txt" comment out
       .FileType = ""
End With
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question