[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now



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
  • 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

873 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