Link to home
Start Free TrialLog in
Avatar of LiMa
LiMa

asked on

Send email from my app automation error

I have an app that allows users to select a file then send it using outlook. This is not an email client or anything it is a document browser but I want the user to be able to select a document click send and it create an email with the attachment. The code I am using is: -

Private Sub cmdSend_Click()
  SendFile (sFileSelected)
end sub

Public Sub SendFile(sFile as string)
dim appOutlook  as application
dim mitItem as mailitem
dim attAttachment as attachement
dim sFileLocation as string
dim sBody as string
dim sSubject as string
dim sRecipient as string

  sFileLocation = sFile
  sSubject = "Document"
  sBody = "Please find requested document attached"
  set appOutlook = CreateObject("Outlook.Application")
  set mitItem = appOutlook.CreateItem(olMailItem)
  sRecipient = "RecipName@site.com"
 
  with mitItem
    .to = srecipient
    .subject = sSubject
    .body = sBody
    .Attachments.Add sFileLocation
    .Display
  end With

  Set mitItem = Nothing
  Set appOutlook = nothing

end sub

This all works fine when I test it using using my laptop but when using the company network I get the following error messages: -

Automation Error - when I click ok to this I then get

Dr Watson exception errors.

The OS on the network computer I am testing this on is NT, with outlook 97. I think that the problem may be something to do with security, but surely there must be a way to send a mail item without breaching the security. If I try this on a computer running Windows 98 I get the error: -

ActiveX component can't create object.

The points I am awrding for this question are for whoever can provide me with a workaround or method to provide the users with the ability to send an email direct from within my application.
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Avatar of barnesd1
barnesd1

Have you tried creating a setup program on your working machine and installing it on the other.  This should include any referenced objects you may be missing.  You may need msoutl85.olb for example.

Hope this helps.
Avatar of LiMa

ASKER

Richie - I couldn't get this to work with my program.

Barnesd1 - I had already done this as the program included other files that needed to be installed (i.e. user controls).

Since posting this question I have Aactually got this working by studying the vbmail sample that comes with VB and using MAPI controls. Thanks for your comments though. I will be asking for this question to be marked as a PAQ.

Thanks again.

LiMa

If you are planning to PAQ, please post what you have found here.
Avatar of LiMa

ASKER

I have modified the vbmail example that is included with visual studio. This makes use of the MAPI controls, the following is what I am using (this is not yet finished): -

*************************************************
Private Sub cmdSend_Click()
On Error GoTo ErrSend
   fLogOn
   ComposeMessage
   
   Exit Sub
   
ErrSend:
   MsgBox "Error No: " & Err.Number & vbCrLf & Err.Description & vbCrLf & "in the Send Click Event", vbCritical, ERRTITLE
   
End Sub

Public Function fLogOn() As Boolean
    ' If a session is already started exit
    If frmSendMail.mapSess.NewSession Then
        MsgBox "Session already established"
        Exit Function
    End If
   
    On Error GoTo errLogInFail
    With frmSendMail.mapSess
        ' Set DownLoadMail to False to prevent immediate download.
        .DownLoadMail = False
        .LogonUI = True ' Use the underlying email system's logon UI.
        .SignOn ' Signon method.
        ' If successful, return True
        fLogOn = True
        ' Set NewSession to True and set0
        ' variable flag to true
        .NewSession = True
      bNewSession = .NewSession
      frmSendMail.mapMess.SessionID = .SessionID
   End With  

End Function


Public Sub ComposeMessage()
On Error GoTo ComposeErr
Dim strMessage As String

   frmSendMail.mapMess.Compose
   frmSendMail.mapMess.Send True
   
   Exit Sub

ComposeErr:
   Debug.Print Err.Number, Err.Description
   Resume Next

End Sub

*************************************************

This provides the basic functionality I require. Thanks again to those who commented. Sorry about the delay in posting this.

LiMa
To Moderators:
Please, PAQ and refund points.
Thanks
Avatar of LiMa

ASKER

I have made a request for this to be PAQ and have the points refunded.

LiMa
ASKER CERTIFIED SOLUTION
Avatar of Mindphaser
Mindphaser

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial