?
Solved

Send email from my app automation error

Posted on 2003-03-06
8
Medium Priority
?
261 Views
Last Modified: 2010-05-01
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.
0
Comment
Question by:LiMa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8079348
0
 
LVL 4

Expert Comment

by:barnesd1
ID: 8079457
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.
0
 

Author Comment

by:LiMa
ID: 8086847
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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8087727
If you are planning to PAQ, please post what you have found here.
0
 

Author Comment

by:LiMa
ID: 8109740
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
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8110619
To Moderators:
Please, PAQ and refund points.
Thanks
0
 

Author Comment

by:LiMa
ID: 8150637
I have made a request for this to be PAQ and have the points refunded.

LiMa
0
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
ID: 8195158
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

764 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