Wrox Programmer Forums
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 11th, 2003, 09:30 PM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to alantodd
Default MAPI

Hi Everyone,

I am building an application in VB 6.0 that needs to be able to send e'mails. I have included the MAPI controls MAPIMessage & MAPISession and all is working well on workstations that are using MS Outlook Express as their e'mail client. However, on the workstations that are using MS Outlook, everytime you send your message, the system generates an error message that reads 'Unspecified Failure has occured'

Not much help unfortunately.

Has anyone else seen this?

Any suggestions?

Thanks,

Alan Todd

P.S. Here is the code:

MAPISess.SignOn
MAPIMess.SessionID = MAPISess.SessionID
MAPIMess.Compose
MAPIMess.RecipAddress = To.Text
MAPIMess.AddressResolveUI = True
MAPIMess.MsgSubject = Subject.Text
MAPIMess.MsgNoteText = Body.Text
MAPIMess.Send
MAPISess.SignOff
 
Old June 12th, 2003, 09:02 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to psychadelic
Default

Hello Alan, Hi everybody,

I am using this piece of code to send mail in my VB app and I've no problem with Ms Outlook. I have cut some of it but I think you could make good use of the following. Hope it works out for you. And if someone wants to add something or comment please do.

regards,

psychadelic

Code:
Private Sub miFMailDirect_Click()

    On Error GoTo err_miFMailDirect_Click

    Dim sFileName As String
    Dim sRecipient As String
    Dim sSubject As String
    Dim sBody As String

    Me.MousePointer = vbHourglass
'   set filename if you want to do attachment, body, recipient etc
    sFileName = ""
    sRecipient = ""
    sSubject = ""
    sBody = ""
    If mapSess.NewSession Then
'       check if session is already opened
    Else
        With mapSess        'MAPISession
'           Set DownLoadMail to False to prevent immediate download.
            .DownLoadMail = False
'           Use the underlying email system's logon UI.
            .LogonUI = True
            .SignOn
            .NewSession = True
            mapMess.SessionID = .SessionID
        End With
        With mapMess        'MAPIMessage
            .MsgIndex = -1
            .Compose
            .RecipIndex = 0
            .RecipType = 1
            .RecipAddress = sRecipient
            .MsgSubject = sSubject
            .MsgNoteText = sBody
'           attachment
            If sFileName <> "" Then
                .AttachmentIndex = 0
                .AttachmentPosition = 0
                .object.AttachmentName = sFileName
                .AttachmentPathName = (sFileName)
            End If
            .AddressResolveUI = False
            .ResolveName
            DoEvents
            .Send False
            MsgBox "Mail has been sent successfully.", vbInformation, App.Title
        End With
        mapSess.SignOff
        mapSess.NewSession = False ' Flag for new session.
    End If
    Me.MousePointer = vbDefault
    Exit Sub

err_miFMailDirect_Click:
    Select Case Err.Number
        Case 32002, 32001
            MsgBox "Mail cannot be sent! Error unknown.", vbExclamation, App.Title
            Me.MousePointer = vbDefault
            Exit Sub
        Case Else
            MsgBox "Error# : " & Err.Number & Chr$(10) & _
                Err.Description, vbExclamation, App.Title & " : miFMailDirect_Click"
            Me.MousePointer = vbDefault
            Exit Sub
    End Select

End Sub
 
Old June 12th, 2003, 09:11 AM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Kilian
Default

Hi a other easy way is like this :
But you have to link the right dll's !!

    Dim outApp As Outlook.Application
    Set outApp = New Outlook.Application
    Dim outMAPI As Outlook.NameSpace
    Dim outFolder As Outlook.MAPIFolder
    Dim outMail As Outlook.MailItem
    Set outApp = New Outlook.Application
    Set outMAPI = outApp.GetNamespace("MAPI")
    Set outFolder = outMAPI.GetDefaultFolder(olFolderOutbox)
    Set outMail = outFolder.Items.Add

    outMail.To = "user@domain.ch"
    outMail.Subject = "Txt-File"
    outMail.Body = "Hallo"
    outMail.Send

cheers Kilian





Similar Threads
Thread Thread Starter Forum Replies Last Post
MAPI question - need help rlorenco Visual C++ 2005 0 March 7th, 2008 06:24 AM
MAPI BobR VB Components 0 February 7th, 2005 07:47 PM
MAPI in Excel raceman Excel VBA 1 January 14th, 2005 02:41 AM
MAPI help kane C++ Programming 2 October 13th, 2004 12:41 AM
MAPI and Domino5 leverell Pro VB 6 1 August 14th, 2003 08:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.