[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Edit Mapi Message before sending

Posted on 2005-04-26
4
Medium Priority
?
490 Views
Last Modified: 2013-12-25
Hello,

I'm trying to make a function that allows me to send a mapi message but it must not send until the user explicit pushes a send button. Wat i want is that a some kind of dialog (standard oulook sendmail dialog) pops up after the mail has been composed. This will give the user the oppurtunity to check the mail before he sends it himself. Downunder is the code i have so far. This code composes a mapi message but at the end it sends the mail and i can't figure out how to show a sendmail dialog.

thanks,
F.


'----------------------------------------------------------------------
' Name   :  SendMail
' Date   :  22-01-1999
' Purpose:  This is the front-end function to the MAPISendMail function.
'           You pass a semicolon-delimited list of To and CC recipients,
'           a subject, a message, and a delimited list of file attachments.
'           This function prepares MapiRecip and MapiFile structures with
'           the data parsed from the information provided using the
'           ParseRecord sub. Once the structures are prepared, the
'           MapiSendMail function is called to send the message.
' Comment:
' Input  :  Subject$  - The text to appear in the subject line of the message
'           Receiver$ - Semicolon-delimited list of names to receive the message
' CC$    :  Semicolon-delimited list of names to be CC'd
' Attach$:  Semicolon-delimited list of files to attach to the message
' Returns:  SUCCESS_SUCCESS if successful, or a MAPI error if not.
'----------------------------------------------------------------------
Public Function SendMail(ByVal Subject$, ByVal Receiver$, ByVal CC$, ByVal Attach$, ByVal Message$) As String
On Error GoTo SendMail_Err
           
    Dim i, cTo, cCC, cAttach                'variables holding counts
    Dim oSession As MAPISession
    Dim oMessages As MAPIMessages
    Dim msg$
     
    'Count the number of items in each piece of the mail message
    cTo = CountTokens(Receiver$, ";")
    cCC = CountTokens(CC$, ";")
    cAttach = CountTokens(Attach$, ";")
   
    'Create arrays to Receiver$re the semicolon delimited mailing
    'information after it is parsed
    ReDim rTo(0 To cTo) As String
    ReDim rCc(0 To cCC) As String
    ReDim rAttach(0 To cAttach) As String
   
    'Parse the semicolon delimited information into the arrays
    ParseTokens rTo(), Receiver$, ";"
    ParseTokens rCc(), CC$, ";"
    ParseTokens rAttach(), Attach$, ";"
       
    'Instantiate Object
    Set oSession = CreateObject("MSMapi.MapiSession")
    Set oMessages = CreateObject("MSMapi.MapiMessages")
     
    'Open Session
    oSession.LogonUI = True
    oSession.SignOn
     
    With oMessages
        .SessionID = oSession.SessionID
        .MsgIndex = -1
       
        'Activate check adresses
        .AddressResolveUI = True
       
        'Receivers
        For i = 0 To cTo - 1
            .RecipType = 1
            .RecipIndex = i
            .RecipAddress = rTo(i)
            .ResolveName
        Next i
       
        'CC's
        For i = 0 To cCC - 1
            .RecipType = 2
            .RecipIndex = i
            .RecipAddress = rCc(i)
            .ResolveName
        Next i
               
        'Subject en messagetext
        .MsgSubject = Subject$
        .MsgNoteText = Message$ & vbCrLf & Space(cAttach)   'reserve spaces for attachments
       
        'Attachments
        For i = 0 To cAttach - 1
            .AttachmentIndex = i
            .AttachmentPosition = Len(.MsgNoteText) + i - cAttach
            .AttachmentPathName = rAttach(i)
        Next i
     
        'Send the mail message
        .Send
       
    End With
     
    'End session
    oSession.SignOff
   
    msg$ = ""
 
SendMail_Exit:
    Set oSession = Nothing
    Set oMessages = Nothing
    SendMail = msg$
    Exit Function

SendMail_Err:
    Select Case Err.Number
        Case 32001: msg$ = "de gebruiker heeft de opdracht geannuleerd"
        Case 32002: msg$ = "er is een onbekende fout opgetreden"
        Case 32011: msg$ = "bijlage(n) niet gevonden"
        Case Else
            RuntimeErr "SendMail"
            msg$ = "er is een fout opgetreden"
    End Select
    Resume SendMail_Exit

End Function
0
Comment
Question by:wacko41
  • 3
4 Comments
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 13865817
try this change

'=================

 'Send the mail message
       .Send True

'=================
0
 
LVL 14

Accepted Solution

by:
Shiju Sasidharan earned 2000 total points
ID: 13865831
0
 

Author Comment

by:wacko41
ID: 13874111
shijusn,

Wow ****ing unbelieveble that it just so simple. I don't know how i've could have missed that. You won't believe all the things i have tried to get it to work and i pretty familiar with VB if i say so myself.

thanks,
0
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 13874272
HI wacko41

;-) Thank u for the points lol
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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

831 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