Get the Redemption dll and reference it.
That is to get around a security issue with code creating and sending an email.
This is working pretty good.
This recieves emails from NOAA weather reports.
I want to send these to my cel, but only a brief message.
Here is an example of one of the emails:
be sure to change the phone numbers.
Private Sub Application_NewMail()
If Hour(Now()) < 22 And Hour(Now()) > 5 Then
Else
Exit Sub
End If
Dim nFirst As Integer
Dim nSecond As Integer
Dim nThird As Integer
Dim nFourth As Integer
Dim nLast As Integer
Dim filter1 As String
filter1 = "EMWIN SERVER"
Dim outlookNameSpace As Outlook.NameSpace
Set outlookNameSpace = Application.GetNamespace("MAPI")
Dim inbox As Outlook.MAPIFolder
Set inbox = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim items As Outlook.items
Set items = inbox.items
items.Restrict ("[Unread] = true") ' i don't think this is working.
' If the mail item matches the specified filter,
' move it to the junk e-mail folder.
Dim mail As Outlook.mailItem
For Each mail In items
If mail.MessageClass = "IPM.Note" And _
InStr(1, UCase(mail.Subject), "BNAWX", vbTextCompare) Then
If mail.MessageClass = "IPM.Note" And (InStr(1, UCase(mail.Body), "TOROHX", vbTextCompare) Or InStr(1, UCase(mail.Body), "SVROHX", vbTextCompare) Or InStr(1, UCase(mail.Body), "FFWOHX", vbTextCompare)) Then
'WX_txt_msg 'this will run the code to send an email for testing.
'answer = MsgBox("Weather Statement", vbInformation)
nFirst = InStr(1, UCase(mail.Body), "* ", vbTextCompare)
nSecond = InStr(nFirst, UCase(mail.Body), "* ", vbTextCompare)
nThird = InStr(nSecond, UCase(mail.Body), "* ", vbTextCompare)
nFourth = InStr(nThird, UCase(mail.Body), "* ", vbTextCompare)
nLast = InStr(nFourth, UCase(mail.Body), "CDT", vbTextCompare)
If nLast = 0 Then
nLast = InStr(nFourth, UCase(mail.Body), "CST", vbTextCompare)
End If
Dim SafeItem, oItem
Set SafeItem = CreateObject("Redemption.SafeMailItem") 'Create an instance of Redemption.SafeMailItem
Set oItem = Application.CreateItem(0) 'Create a new message
SafeItem.Item = oItem 'set Item property
SafeItem.Recipients.Add "6155551212@vtext.com"
SafeItem.Recipients.Add "6155551212@vtext.com" 'bob cel
SafeItem.Recipients.ResolveAll
If InStr(1, UCase(mail.Body), "TOROHX", vbTextCompare) Then
SafeItem.Subject = "Tornado Warning"
End If
If InStr(1, UCase(mail.Body), "SVROHX", vbTextCompare) Then
SafeItem.Subject = "Severe Thndrstrm Warning"
End If
If InStr(1, UCase(mail.Body), "FFWOHX", vbTextCompare) Then
SafeItem.Subject = "Flash Flood Warning"
End If
SafeItem.Body = Trim(Mid$(mail.Body, nFirst + 2, nSecond - nFirst)) & "." & Trim(Mid$(mail.Body, nFourth + 2, nLast - nFourth))
SafeItem.Send
Else
' enable for testing only.
'Dim SafeItem1, oItem1
'Set SafeItem1 = CreateObject("Redemption.SafeMailItem") 'Create an instance of Redemption.SafeMailItem
'Set oItem1 = Application.CreateItem(0) 'Create a new message
'SafeItem1.Item = oItem1 'set Item property
'SafeItem1.Recipients.Add "6155551212@vtext.com"
'SafeItem1.Recipients.Add "6155551212@vtext.com" 'bob cel
'SafeItem1.Recipients.ResolveAll
'SafeItem1.Subject = mail.Subject
'SafeItem1.Body = Trim(Mid$(mail.Body, InStr(1, UCase(mail.Body), ".NOW...", vbTextCompare) + 8, 80))
'SafeItem1.Send
End If
' mail.Move (outlookNameSpace.GetDefaultFolder( _
' Outlook.OlDefaultFolders.olFolderJunk))
Else
'just a regular email... let it through without doing anything.
'answer = MsgBox("other", vbInformation)
End If
Exit For 'i just want the first email, so i exit here.
Next
End Sub
Tolerance and diversity, or in-tolerance and perversity.
You Decide.