Posted on 2004-10-20
Medium Priority
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 = “smtg@microsoft.com”
    aryRecipient(0).Address = “smtg@microsoft.com”
    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
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
LVL 16

Expert Comment

ID: 12368564
Based on our comments in http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21173839.html:

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 bizarre...no 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

719 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