Consulting

Results 1 to 9 of 9

Thread: PC details via e-Mail

  1. #1

    PC details via e-Mail

    Dear all,
    I am a new member of this forum and need your help.

    We have a requirement in the IT dept. that whenever an email is sent to a particular email address e.g. adc@xyz.com, the computer name, IP Address and user name of the user should be automatically placed in the body of the message.

    This requirement is there to simplify the PC details gathering by the helpdesk agents.

    Can this be achieved via outlook. Our user use outlook 2010 & 2007.

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Yes, I recommend a COM addin but you can do this using VBA as well.

    For computer name, use

    [vba]Environ("COMPUTERNAME")[/vba]

    For IP address retrieval, see http://stackoverflow.com/a/949986/190829

    For username , use

    [vba]Session.CurrentUser[/vba]

    Putting it all together:

    [vba]
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim username As String
    Dim computerName As String
    Dim ipaddress As String
    Dim msg As Outlook.mailItem
    ipaddress = GetIPAddress
    username = session.CurrentUser
    computerName = Environ("COMPUTERNAME")
    If TypeName(Item) = "MailItem" Then ' it's an email ...
    Set msg = Item
    With msg
    If .To = "adc@xyz.com" Then ' it's going to the target address, add details to msg
    .Body = .Body & vbNewLine & vbNewLine & _
    "Computer Name: " & computerName & vbNewLine & _
    "IP Address: " & ipaddress & vbNewLine & _
    "Username: " & username
    .Save
    End If
    End With
    End If
    End Sub
    [/vba]
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  3. #3
    Thanks JP2112.

    Can you please give me more step by step kind of a thing.

    I pasted the code in the "Thisoutlooksession" and saved. I tried to send an email to my personal mail (After changing the recepient in the cose) but it didnt work.

    Where should I put the code?

  4. #4
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    The code goes in ThisOutlookSession module. You should restart Outlook after pasting or editing any event handlers.

    You would also need to visit that Stack Overflow page and use whatever method you want to get the IP address. I recommend the code posting in the accepted answer.
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  5. #5
    JP,

    Thanks for your help. However, I am really new to this. I pasted in ThisOutlookSesssion, restarted outlook. 'Yet it didnt work!!!

    What is stack overflow page?

    I maybe doing something wrong...

  6. #6
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Double check that you have pasted the code in the correct place. See Where do I put my Outlook VBA code? for placement assistance.

    Do you already have an Application_ItemSend Event in your ThisOutlookSession module? If so, you need to integrate the above code into the existing event. You cannot have more than one Application_ItemSend Event.

    The Stack Overflow page is the one I linked to in my previous post. (I recommend the code posted in the accepted answer.) You need to visit that page and take whatever code you want to use to get the local IP address and paste it into ThisOutlookSession.

    After restarting Outlook, you should set a breakpoint in the code (press F9) and then send an email which you think should trigger the code in the event. That's how I debug event handlers.
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  7. #7
    Hi JP2112,

    Really appreciate your help.

    I have only one Application_ItemSend event I believe. I attached a screenshot of my outlook VBA. Maybe this would clear the current situation.
    Attached Images Attached Images

  8. #8
    Hi JP2112,

    I got it working. My macro security settings were set to "Notifications for digitally signed macros". I selected "Enable all macros" and it worked.

    Thanks for your help.

  9. #9
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Great news! Congratulations!
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •