jimleeder123 Posted July 27, 2015 Share Posted July 27, 2015 I am looking to add code into Outlook. I want to use visual basic to check an e-mail's body text and print if it contains the word "cash". It will contain either that or PayPal. So basically all I wanna know is what to put in the if statement to check for it. I have the code to use to print it. I imagine it would be something like " if mail.body.text = cash" or something like that. I'm new to Visual Basic so any help will be welcomed. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/297491-visual-basic-check-e-mail-body-text/ Share on other sites More sharing options...
Psycho Posted July 27, 2015 Share Posted July 27, 2015 The answer is it depends. I know a good bit about VBScript as opposed to Visual Basic, but it is mostly transferable. If you only need to know if the body contains the word "cash" you would still need to account for variations such as "Cash", "CASH", etc. So, I would do the following: Convert the body to all lower or upper case characters. Then check for the target word. That is the simplest solution, but has one downfall. If 'cash' is contained in another word as opposed to being its own word it would still provide a match. To work around that you would need to use Regular Expression which is more complicated. Based on your actual need you may need to go that route. Note that if this is for some type of spam detection process you will likely get a lot of emails falling through the cracks since they will use other characters to get around detection, e.g. "ca$h". So, you could use the LCase function to convert the body to all lower case and then the InStr function to see if your target word is contained in the content. Here is some mock code: VAR bodyText = LCase(mail.body.text) IF InStr (bodyText, "cash", vbTextCompare) Then ' "cash" does exist in the body Else ' "cash" does not' exist in the body End If Quote Link to comment https://forums.phpfreaks.com/topic/297491-visual-basic-check-e-mail-body-text/#findComment-1517487 Share on other sites More sharing options...
jimleeder123 Posted July 28, 2015 Author Share Posted July 28, 2015 Ok thanks. It will contain either cash or paypal depending on the method the customer chooses. The email gets printed out, and shouldn't be printed if it says paypal. We want to print the email only when the matching paypal receipt is recieved. Do you know some VB code that will check for the matching email once the paypal email has arrived? They will both either have the order ID in the subject or body text. Quote Link to comment https://forums.phpfreaks.com/topic/297491-visual-basic-check-e-mail-body-text/#findComment-1517521 Share on other sites More sharing options...
jimleeder123 Posted July 28, 2015 Author Share Posted July 28, 2015 I've tried the following code to see if a message box appears when an email comes in with "cash" in the body text (have a rule set up to check them). But its not working, any help please? Function payment() Var bodyText = LCase(Mail.Body.Text) If InStr(bodyText, "cash", vbTextCompare) Then MsgBox "Paid by Cash" Else MsgBox "Paid by PayPal" End If End Function Sub CheckMail(MyMail As MailItem) MsgBox (payment) End Sub Quote Link to comment https://forums.phpfreaks.com/topic/297491-visual-basic-check-e-mail-body-text/#findComment-1517522 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.