Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

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.
0
LiMa
Asked:
LiMa
1 Solution
 
Richie_SimonettiIT OperationsCommented:
0
 
barnesd1Commented:
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
 
LiMaAuthor Commented:
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
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.

 
Richie_SimonettiIT OperationsCommented:
If you are planning to PAQ, please post what you have found here.
0
 
LiMaAuthor Commented:
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
 
Richie_SimonettiIT OperationsCommented:
To Moderators:
Please, PAQ and refund points.
Thanks
0
 
LiMaAuthor Commented:
I have made a request for this to be PAQ and have the points refunded.

LiMa
0
 
MindphaserCommented:
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now