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.
[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]
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.
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.
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.