Solved

MAPISendMail giving error 11 (Attachment not found)

Posted on 2001-07-13
4
2,320 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 50 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vbModal 12 66
Export PDF Form fields to Access  or Excel  in Tab order 16 113
checkbox to hide entire section 10 63
Fastest way to find and count same items VB6 16 47
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

726 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