Solved

MAPISendMail giving error 11 (Attachment not found)

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

861 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