Solved

MAPISendMail giving error 11 (Attachment not found)

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

813 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

12 Experts available now in Live!

Get 1:1 Help Now