Solved

MAPISendMail giving error 11 (Attachment not found)

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now