Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event code for receiving a new email, and process it.

Status
Not open for further replies.

rssql

Programmer
Jul 22, 2002
87
US
When I receive an email from a certain sender, i wish to open it, parse through it to grab certain words, then have it create a new email to send.

How might this be done?
I am fluent with Access and Excel code.


Fighting for the cause of tolerance and diversity, or was it in-tolerance and perversity? Just different sides of the same coin.
 
So far, i have read about CDO.
anyone have a clue?

Tolerance and diversity, or in-tolerance and perversity.
You Decide.
 
Hey RS,

If you're proficient in VB coding you can probably figure out something from this link. It's about writing VB code straight into Outlook. I've been thinking I could use the Application_NewMail event and place parameters on it based on subject or from field, and having that call an autoexec in access to get the attachments into my database. If you are talking server-level it probably won't help you so much, but it might be a good place to start. Let me know if you figure anything out.

Alex

 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top