Posted on 2004-10-20
Last Modified: 2013-11-13
I'm trying to use MAPI to send a mail with MS Outlook as the default email client.
Local machine running XPpro and using smtp email account as default. My application utlizes a custom form MS Outlook Form.

The following code works with no problem for Outlook 2000, meaning that it opens a new MailItem Form with the info, and after clicking send it puts the message in outbox…and it can be sent (Outlook 2000 in Internet Mode).

Now the problems appear in Outlook 2002 and 2003. It also creates the MailItem Form with the info, when I send the meassge, it moves from the outbox to the inbox as undelverable mail. When I look at email properties in the message form the E-mail Type field is the same the email address - with internet type defaulted. When I click on internet type button the E-mail Type field changes to SMTP, with this change, I can send the email, and it goes out with any problems. Like wise when I try to email in the standard manner, open contact dclick on the email address (btw: here it's defaulted to smtp) create and send an email.

So how do I set E-mail Type from MAPI, what am I missing here … if someone encountered this and has a workaround or knows what’s causing this (maybe how to set the transport protocol settings) or whatever - appreciate your taking time in responding to this.

Not sure at this point if it's local settings, Custom form settings or MAPI code, the idea here is that code should adopt the clients default email settings and email should go out without any manual changes or errors.

_________________________Code Sample:____________________________________________

Private Type MAPIMessage
    Reserved       As Long
    Subject        As String
    NoteText       As String
    MessageType    As String
    DateReceived   As String
    ConversationID As String
    Flags          As Long
    RecipCount     As Long
    FileCount      As Long
End Type

Private Type MapiRecip
    Reserved   As Long
    RecipClass As Long
    Name       As String
    Address    As String
    EIDSize    As Long
    EntryID    As String
End Type

Private Type MapiFile
    Reserved As Long
    Flags    As Long
    Position As Long
    cPathName As String
    FileName As String
    FileType As String
End Type

Private Declare Function MAPILogon Lib "MAPI32.DLL" _
    (ByVal UIParam&, ByVal User$, ByVal Password$, ByVal Flags&, _
    ByVal Reserved&, Session&) As Long
Private Declare Function MAPILogoff Lib "MAPI32.DLL" _
    (ByVal Session&, ByVal UIParam&, ByVal Flags&, ByVal Reserved&) As Long
Private Declare Function MAPISendMail Lib "MAPI32.DLL" _
    Alias "BMAPISendMail" (ByVal Session&, ByVal UIParam&, _
    Message As MAPIMessage, Recipient() As MapiRecip, _
    File() As MapiFile, ByVal Flags&, ByVal Reserved&) As Long
Private Declare Function MAPISendDocuments Lib "MAPI32.DLL" _
    (ByVal UIParam&, ByVal DelimStr$, ByVal FilecPaths$, _
    ByVal FileNames$, ByVal Reserved&) As Long

Private Sub btnSend_Click()
Dim l  As Long
Dim lngSession    As Long
Dim udtMessage    As MAPIMessage
Dim strSubject As String  
Dim strBody As String

   strSubject = "Mapi Problem"
   strBody = “in Outlook XP, 2003“

    ReDim aryRecipient(0) As MapiRecip  
    aryRecipient(0).Name = “”
    aryRecipient(0).Address = “”
    aryRecipient(0).RecipClass = MAPI_TO

    ReDim aryFile(0) As MapiFile

    With aryFile(0)    
           .FileName = “C:\Windows\Notepad.exe”
            .cPathName = “C:\Windows\Notepad.exe”
            .Position = Len(strBody) -  1
            .FileType = ""
            .Reserved = 0
     End With

    With udtMessage
        .Subject = strSubject
        .NoteText = strBody
        .Flags = 0
        .FileCount = 1
        .RecipCount = 1
        .Reserved = 0
        .DateReceived = ""
        .MessageType = ""
    End With
    l = MAPILogon(Me.hWnd, "", "", MAPI_LOGON_UI, 0, lngSession)
    l = MAPISendMail(lngSession, Me.hWnd, udtMessage, aryRecipient, aryFile, _ MAPI_DIALOG, 0)    
    l = MAPILogoff(lngSession, 0, 0, 0)
End Sub


Question by:Tlogix
  • 2
LVL 16

Expert Comment

ID: 12368564
Based on our comments in

I might be being really dense here but I can't find this 'Email type' setting anywhere in the Mail options, properties, or from address properties...

Do a small test:

      MsgBox ActiveInspector.CurrentItem.Class
      MsgBox ActiveInspector.CurrentItem.MessageClass

before and after you manually set the 'Email type' (you may have to save the mail first).  Maybe these values will be different and you can use that...


Author Comment

ID: 12425431

Sorry, those didn't help. I have looked all over the web and several forums...really references or answers anywhere...what could be the problem?

I'll try to explain again:

In outlook 2002, open a conatct form, click on the email address for the contact and the email properties from should pop-up. The third item is "email Type". By default, the email type is SMPT for my default acount and I can send mail with no problems.

When I use my mapi code, the email doen't go out and I get an undeliverable message "none of your accounts could send this message. When i check the 'email type' in the email properties from the Message from (same form as above) by clicking on the address, the 'Email Type' is set to Internet type. When I click on the internet type button and the value changes to SMTP, I can send the email without any problem.

My Question is this: Why is this not defaulting to my Default settings? How can I make it do that?
Is it in the Mapi code, a local setting or what?
Really appreciate any help you can Offer.

LVL 16

Accepted Solution

jimbobmcgee earned 500 total points
ID: 12522723
OK, I found the setting you are referring to.  I couldn't find it before because all the contacts I was looking at were Exchange users.  The following code will change the email type to a string supplied by you.  I don't know how long it changes it for -- if you double click on the address and check it manually again it seems to change back -- but, as you will see from the two message boxes, it does appear to change something:

    Sub ChangeType()
        Dim Recip As Recipient
        Dim AddEnt As AddressEntry
        For Each Recip In ActiveInspector.CurrentItem.Recipients
            Set AddEnt = Recip.AddressEntry
            MsgBox AddEnt.Type
                   AddEnt.Type = "SoMe TyPe"
            MsgBox AddEnt.Type
        Next Recip
    End Sub



Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Paint/Redraw window while dragging 16 68
message box in access 4 41
How to Add / Edit Windows Menu 4 49
Macro Excel - Multiple If conditions 2 62
Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

932 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

13 Experts available now in Live!

Get 1:1 Help Now