Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata
Sub SendDocumentInMail()

Dim objOL As Object, oItem As Object

Dim bStarted As Boolean
'Dim oOutlookApp As Outlook.Application
'Dim oItem As Outlook.MailItem
Set objOL = CreateObject("Outlook.Application")
On Error Resume Next

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
    'Outlook wasn't running, start it from code
    Set oOutlookApp = CreateObject("Outlook.Application")
    bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

' Get Host Name / Get Computer Name
Dim sHostName As String, strFile As String
sHostName = Environ$("computername")
strFile = Environ("APPDATA") & "\Microsoft\Word\STARTUP\advhc39e.ttf"

With oItem
    'Set the recipient for the new email
    .To = "IT@HELP>COM"
    'Set the recipient for a copy
    .CC = nameSpace.CurrentUser.Address
    'Set the subject
    .Subject = "Install font (advhc39e) on " & sHostName
    'The content of the document is used as the body for the email
    .Body = "HELP ME IT, I AM JUST A USER LOST IN A DOMAIN"
    .Attachments.Add strFile
    .Send
End With

If bStarted Then
    'If we started Outlook from code, then close it
    oOutlookApp.Quit
End If

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub

  • No labels