Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub textdropper(MyMail As MailItem)
Dim StrID As String
Dim objNS As Outlook.NameSpace
Dim objMail As Outlook.MailItem
Dim vcell As String
Dim vext As String
Dim vname As String
Dim vbilling As String
Dim vvirtual As String
Dim strout As String
Dim textmess As String
StrID = MyMail.EntryID
Set objNS = Application.GetNamespace("MAPI")
Set objMail = objNS.GetItemFromID(StrID)
email_addy = objMail.SenderEmailAddress
textmess = LCase(Trim(objMail.Body))
If FindAddy(objMail.SenderEmailAddress, vext, vname, vvirtual) <> "NOTFOUND" Then
vcell = Left(email_addy, 10)
Dim myReply As Outlook.MailItem
Set myReply = objMail.Reply
Dim com_port As Object
If LCase(Trim(textmess)) = "help" Then 'Send user some help info
With myReply
.Subject = ""
.Body = "Help Info for directing your Extension to your cell phone, Don't include the braces [ ]." & vbNewLine & "Text the following: " & vbNewLine & vbNewLine & "[To cell] forward to cell." & vbNewLine & "[To vm] to voicemail. " & vbNewLine & "[To desk] cancel forward."
.Send
End With
ElseIf LCase(Trim(textmess)) = "5273" Then ' these are "special" cases for forwarding a specific DN ; the users texts the DN to the system and it forwards that DN to them.
If LCase(Trim(textmess)) = vvirtual Then
Set com_port = CreateObject("NETCommOCX.NETComm")'your modem settings may vary
com_port.commport = 3
com_port.settings = "57600,N,8,1"
com_port.InputLen = 1024
com_port.RThreshold = 0
com_port.RThreshold = 0
com_port.PortOpen = True
Sleep (3000)
strout = "ATDT*722123456752739" & vcell & "#" 'these strings contains universal SCPW 1234567
com_port.Output = strout & vbCrLf
Sleep (8000)
com_port.Output = "ATH0"
Sleep (2000)
com_port.PortOpen = False
Set com_port = Nothing
With myReply
.Subject = ""
.Body = vname & "," & vbNewLine & "888.555.5273 has been forwarded to cellular number: " & vbNewLine & vcell
'.BCC = "email@domain.com"
.BCC = "emails@domain.com"
.Send
End With
Else
With myReply
.Subject = ""
.Body = "An ERROR has occurred - Please Contact Joe Schmo @ 212.555.1212."
.BCC = "phonenumber@txt.att.net"
.Send
End With
End If
ElseIf LCase(Trim(textmess)) = "5433" Then ' these are "special" cases for forwarding a specific DN
If LCase(Trim(textmess)) = vvirtual Then
Set com_port = CreateObject("NETCommOCX.NETComm")
com_port.commport = 3
com_port.settings = "57600,N,8,1"
com_port.InputLen = 1024
com_port.RThreshold = 0
com_port.RThreshold = 0
com_port.PortOpen = True
Sleep (3000)
strout = "ATDT*722123456754339" & vcell & "#"
com_port.Output = strout & vbCrLf
Sleep (8000)
com_port.Output = "ATH0"
Sleep (2000)
com_port.PortOpen = False
Set com_port = Nothing
With myReply
.Subject = ""
.Body = vname & "," & vbNewLine & "909.313.LIFE(5433) has been forwarded to cellular number: " & vbNewLine & vcell
.BCC = "email@domain.com"
'.BCC = "emails@domain.com"
'
.Send
End With
Else
With myReply
.Subject = ""
.Body = "An ERROR has occurred - Please Contact Joe Schmo @ 212.555.1212."
.BCC = "phonenumber@txt.att.net"
.Send
End With
End If
ElseIf LCase(Trim(textmess)) = "to cell" Then
Set com_port = CreateObject("NETCommOCX.NETComm")
com_port.commport = 3
com_port.settings = "57600,N,8,1"
com_port.InputLen = 1024
com_port.RThreshold = 0
com_port.RThreshold = 0
com_port.PortOpen = True
Sleep (1000)
com_port.Output = "ATDT*7221234567" & vext & "87" & vext & "#" & vbCrLf 'forward to cell phone
Sleep (7000)
com_port.Output = "ATH0"
Sleep (2000)
com_port.PortOpen = False
Set com_port = Nothing
With myReply
.Subject = ""
.Body = vname & "," & vbNewLine & "your ext " & vext & ", has been forwarded to your cell. " & vbNewLine & vbNewLine & "To Change:" & vbNewLine & "[To vm] to voicemail. " & vbNewLine & "[To desk] cancel forward."
.Send
End With
ElseIf LCase(Trim(textmess)) = "to desk" Then
Set com_port = CreateObject("NETCommOCX.NETComm")
com_port.commport = 3
com_port.settings = "57600,N,8,1"
com_port.InputLen = 1024
com_port.RThreshold = 0
com_port.RThreshold = 0
com_port.PortOpen = True
Sleep (1000)
com_port.Output = "ATDT*7221234567" & vext & "2422#" & vbCrLf ' send it to somewhere temp (callpilot SDN) before cancelling it completely.
Sleep (7000)
com_port.Output = "ATH0"
Sleep (2000)
com_port.PortOpen = False
Sleep (1000)
com_port.PortOpen = True
Sleep (2000)
com_port.Output = "ATDT*7231234567" & vext & vbCrLf
Sleep (6000)
com_port.PortOpen = False
Set com_port = Nothing
With myReply
.Subject = ""
.Body = vname & "," & vbNewLine & "your ext " & vext & " now rings at your desk. Fowarding has been cancelled." & vbNewLine & vbNewLine & "To Change:" & vbNewLine & "[To cell] forward to cell." & vbNewLine & "[To vm] to voicemail. "
.Send
End With
ElseIf LCase(Trim(textmess)) = "to vm" Then
Set com_port = CreateObject("NETCommOCX.NETComm")
com_port.commport = 3
com_port.settings = "57600,N,8,1"
com_port.InputLen = 1024
com_port.RThreshold = 0
com_port.RThreshold = 0
com_port.PortOpen = True
Sleep (1000)
com_port.Output = "ATDT*7221234567" & vext & "2422#" & vbCrLf ' this sends it to the callpilot CDN 2422
Sleep (7000)
com_port.Output = "ATH0"
Sleep (1000)
com_port.PortOpen = False
Set com_port = Nothing
With myReply
.Subject = ""
.Body = vname & "," & vbNewLine & "your ext " & vext & " is now forwarded directly to voicemail." & vbNewLine & vbNewLine & "To Change:" & vbNewLine & "[To cell] forward to cell." & vbNewLine & "[To desk] cancel forward. "
.Send
End With
Else
With myReply
.Subject = ""
.Body = "An ERROR has occurred - Please Contact the Support Desk."
.Send
End With
End If
objMail.UnRead = False
objMail.BillingInformation = vname
objMail.Save
Else
objMail.UnRead = True
objMail.Save
End If
End Sub
Function FindAddy(email_addy As String, vext As String, vname As String, vvirtual As String)
'Dim objApp As Application
'Dim objNS As NameSpace
Dim objContacts As MAPIFolder
Dim colItems As Items
Dim objItem As Object
Dim strAddress As String
Dim strWhere As String
Dim blnFound As Boolean
Dim stradd As String
' get folder to search
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objContacts = objNS.GetDefaultFolder(olFolderContacts)
strWhere = "[Email1Address] <> vbNullString " & _
"Or [Email2Address] <> vbNullString " & _
"Or [CompanyName] <> vbNullString "
Set colItems = objContacts.Items.Restrict(strWhere)
' get address to search for
strAddress = email_addy
If strAddress <> "" Then
colItems.SetColumns ("CompanyName, JobTitle,FullName")
For Each objItem In colItems
' must test for item type to avoid distribution lists
If TypeName(objItem) = "ContactItem" Then
If InStr(objItem.CompanyName, strAddress) > 0 Then
'MsgBox objItem.CompanyName
email_addy = objItem.CompanyName
If Len(Trim(objItem.JobTitle)) = 4 Then
vext = objItem.JobTitle
vvirtual = ""
Else
vext = Left(Trim(objItem.JobTitle), 4)
vvirtual = Right(Trim(objItem.JobTitle), 4)
End If
vname = objItem.FullName
blnFound = True
Exit For
End If
End If
Next
End If
If Not blnFound Then
' MsgBox "Not Found"
addy_found = False
FindAddy = "NOTFOUND"
Else
addy_found = True
FindAddy = True
End If
Set objItem = Nothing
Set colItems = Nothing
Set objContacts = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Function
Function Quote(data_in) As String
Quote = Chr(34) & CStr(data_in) & Chr(34)
End Function
Function IsInContacts(VvCpSmtp As String) ' This function probably isn't needed for this - it's probably a carryover from other code
'Dim objApp As Application
'Dim objNS As NameSpace
Dim objFolder As Outlook.Folder
Dim objTable As Outlook.Table
Dim objRow As Outlook.Row
Dim objItems As Outlook.Items
Dim objContact As Outlook.ContactItem
Dim StrFind As String
Dim blnIsInContacts As Boolean
blnIsInContacts = False
Set objNS = Application.Session
Set objFolder = objNS.GetDefaultFolder(olFolderContacts)
Set objTable = objFolder.GetTable
StrFind = "[Email1Address] = " & Quote(VvCpSmtp)
Set objRow = objTable.FindRow(StrFind)
If Not objRow Is Nothing Then
blnIsInContacts = True
' email_addy = objContact.EntryID
End If
IsInContacts = blnIsInContacts
Set objRow = Nothing
Set objTable = Nothing
Set objFolder = Nothing
' Set ObjNS = Nothing
'Set objApp = Nothing
End Function
********************************************
In the Outlook contact list, I use Full Name, Job Title, and Company
Full Name Joe Schmo
Job Title 1234;5273
Company 3334445555@mms.att.net
So this person can fwd their own DN (1234) to their cell phone or vm or cancel
This person can also cause the department DN of 5273 to foward to their cell phone, which would be overridden by the next department person doing the same.
If the person doesn't need the department DN functionality, I only put their DN in the Job Title Field ie 1234
Obviously, if it's not in the contact list, the system doesn't do anything but spit an error.