Solved

VB6 MAPI MS OUTLOOK 2002 SEND EMAIL TYPE PROBLEM

Posted on 2004-10-20
5
882 Views
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.

Thanks.
_________________________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

___________________________________________________________________________


 
0
Comment
Question by:Tlogix
  • 2
5 Comments
 
LVL 16

Expert Comment

by:jimbobmcgee
Comment Utility
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...

J.
0
 

Author Comment

by:Tlogix
Comment Utility
Jim,

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.

Thanks.
0
 
LVL 16

Accepted Solution

by:
jimbobmcgee earned 500 total points
Comment Utility
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

HTH

J.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…

772 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