Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MAPI to select mail recipient

Status
Not open for further replies.

assets

Technical User
Oct 23, 2002
574
AU
The following code (less MAPI) Which I added in a different forum will send email to name in address line. What I want to do is have the new mail window without an address so you can add your own.
Code:
Function SendIt(sRecip As String, sTitle As String, sText As String, sFile As String) As Boolean
Dim strTemp      As String
 Dim strError      As String
 Dim lngIndex      As Long
 Dim iFileCount As Integer
     
 Dim mRecip(0) As MapiRecip, mFile() As MapiFile, mMail As MAPIMessage
 Dim lSess As Long, lRet As Long
 

 On Error GoTo ErrorHandler
 SendIt = False
     
 'Add 2 trailing spaces to the text, this will be the position where the attachment goes to
 sText = sText & "  "
     
 'Recipient
 With mRecip(0)
      .Name = sRecip
      .RecipClass = MAPI_TO
   End With
     
    'File to send?
   If sFile <> "" Then
      ReDim mFile(0)
      With mFile(0)
      .FileName = sFile
      .PathName = sFile
      .Position = Len(sText) - 1
      .FileType = ""
      .Reserved = 0
   End With
      iFileCount = 1
   End If
     
    'Create Mail
   With mMail
      .Subject = sTitle
      .NoteText = sText
      .Flags = 0
      .FileCount = iFileCount
      .RecipCount = 1
      .Reserved = 0
      .DateReceived = ""
      .MessageType = ""
   End With
     
   'Post it
   'Logon: User = "" and Password = ""
  lRet = MAPILogon(0, "", "", MAPI_LOGON_UI, 0, lSess)
   If lRet <> SUCCESS_SUCCESS Then
       strError = "Error logging into messaging software. (" & CStr(lRet) & ")"
        GoTo ErrorHandler
   End If
     
    'Send the mail to the given recipients with the attached file without showing a dialog
   lRet = MAPISendMail(lSess, 0, mMail, mRecip, mFile, MAPI_NODIALOG, 0)
   If lRet <> SUCCESS_SUCCESS And lRet <> MAPI_USER_ABORT Then
        If lRet = 14 Then
            strError = "Recipient not found"
        Else
           strError = "Error sending: " & CStr(lRet)
        End If
        GoTo ErrorHandler
    End If
     
    lRet = MAPILogoff(lSess, 0, 0, 0)
     
   SendIt = True
    Exit Function
     
ErrorHandler:
    If strError = "" Then strError = Err.Description
    Call MsgBox(strError, vbExclamation, "MAPI-Error")
End Function

Sub Autoclose()
 

    Dim strDocName As String
    Dim intPos As Integer


      intPos = InStrRev(strDocName, ".")
        
strDocName = ActiveDocument.FullName
     
        SendIt "me@mysite.com", "A new Access Card for person below", "Hi, read this:", strDocName
    Application.ScreenUpdating = True
   End Sub

Never give up never give in.

There are no short cuts to anything worth doing :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top