PDA

View Full Version : PC details via e-Mail



ahassan99
08-28-2012, 04:56 AM
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.

JP2112
08-29-2012, 01:17 PM
Yes, I recommend a COM addin but you can do this using VBA as well.

For computer name, use

Environ("COMPUTERNAME")

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

For username , use

Session.CurrentUser

Putting it all together:


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

ahassan99
08-30-2012, 08:26 AM
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?

JP2112
08-31-2012, 08:34 AM
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.

ahassan99
08-31-2012, 01:48 PM
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... :(

JP2112
09-02-2012, 07:02 AM
Double check that you have pasted the code in the correct place. See Where do I put my Outlook VBA code? (http://www.jpsoftwaretech.com/outlook-vba/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.

ahassan99
09-02-2012, 07:24 PM
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.

ahassan99
09-05-2012, 11:38 PM
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.

JP2112
09-14-2012, 12:20 PM
Great news! Congratulations! :clap: