• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Vba to check name in the body and email ID.

Jagdev Singh

Active Member
Hi Experts

Is it possible to check the name of the person whom we address the mail and match it with the name in the email ID.

Ex -

ID - Jagdevsingh@

Mail body,

Hi Jagdev

Can we check if both the names are same or not.

Regards,
JD
 
Hi Marc

Please find the screen-shot attached. In this case it should throw a pop-up that the ID is not matching with the name.

Regards,
JD
 

Attachments

  • Capture.PNG
    Capture.PNG
    7.2 KB · Views: 7
Hi Luke

Could you please help me with the code. I am not able to relate it.

Regards,
JD

JD

If u have the code for mail then post it here so that we can optimize it for the subject.

OR

Arrange something in ur code like as below!!

Code:
If Not InStr(ID, Name) > 0 Then MsgBox "Name Mismatch": Exit Sub
 
Hi Deepak


Thanks for the code! As per the code in question here, I don't have any code for this as of now. I even don't know which application is more preferable Excel or Outlook to deal with this issue. The query just popped-up in my mind and I thought to check with you guys here. Could you please guide me with this. I just do not want to send or address wrong opponent in my emails, so would like to add filter which will throw pop-up message in case if the name doesn’t match with the ID.


Regards,

JD
 
JD,

Do the search on the forum & you will lots of post for the email, outlook,mail merge.

Or check Ron's site for the same.

Choose wisely a code and append the same.

Let us know for the changes.
 
Hi Deepak

I find the below Outlook code which throws a pop-msg after I click on the send button and display the ID (To) And subject line. Is it possible to pull the name of the addressee as well with it.

Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim strSubject As String
Dim StrTo As String


strSubject = Item.Subject
StrTo = Item.To

Prompt$ = "You’re about to send this email with the subject [" & strSubject & " - " & StrTo & "]. Are you sure you want to send the Mail?"

If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Email Confirmation") = vbNo Then Cancel = True

End Sub

Regards,
JD
 
Hi Deepak,

It is throwing an error 5 " invalid procedure call". I am able to pull the ID (To) with the code and now I want the name from the body

Hi Jagdev

This in the pop-up

Regards,
JD
 
Check it.

where

What body as used is

Hello Deepak,

Welcome!!



Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim strSubject As String
Dim StrTo As String
Dim strBody As String

strSubject = Item.Subject
StrTo = Item.To
strBody = Mid(Item.Body, InStr(Item.Body, " ") + 1, InStr(Item.Body, ",") - InStr(Item.Body, " ") - 1)


Prompt$ = "Verify it " & vbNewLine & "Subject - " & strSubject & vbNewLine & _
            "Mail to - " & StrTo & vbNewLine & _
            "Person - " & strBody & vbNewLine & vbNewLine & "Are you sure you want to send the Mail?"

If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Email Confirmation") = vbNo Then Cancel = True

End Sub
 
Hi Deepak

Bingo you are a champ!

Just one random qusetion say if I have list of 20 ID who interact with eachother several time in a day. We will be using this code in all our machines. The query is the pop-up should not appear when ppl from this list communicate with eachother. The pop-up should appear if they send email to anyone out of this group of 20 ppl. Is this possible.

Regards,
JD
 
JD,

Check this modified with error control too!!

Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim strSubject As String
Dim StrTo As String
Dim strBody As String
Dim mypeople As String

On Error GoTo e
strSubject = Item.Subject
StrTo = Item.To
strBody = Mid(Item.Body, InStr(Item.Body, " ") + 1, InStr(Item.Body, ",") - InStr(Item.Body, " ") - 1)

mypeople = "abc@xyz.com,abc1@xyz.com,abc2@xyz.com,abc3@xyz.com,abc4@xyz.com,abc5@xyz.com,abc6@xyz.com,abc7@xyz.com,abc8@xyz.com,abc9@xyz.com,abc10@xyz.com,abc11@xyz.com,abc12@xyz.com,abc13@xyz.com,abc14@xyz.com,abc15@xyz.com,abc16@xyz.com,abc17@xyz.com,abc18@xyz.com,abc19@xyz.com,abc20@xyz.com"
If InStr(mypeople, StrTo) > 1 Then Exit Sub

Prompt$ = "Verify it " & vbNewLine & "Subject - " & strSubject & vbNewLine & _
            "Mail to - " & StrTo & vbNewLine & _
            "Person - " & strBody & vbNewLine & vbNewLine & "Are you sure you want to send the Mail?"

If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Email Confirmation") = vbNo Then Cancel = True
Exit Sub

e:
Cancel = True
MsgBox "Pls Recheck as per pattern : To[@], Subject[<>], Body[ ,]"
End Sub
 
Hi Deepak

I tried without changing it and also with changing it, but the pop-up still appears. Please find the screen-shot attached with the mail.

Regards,
JD
 

Attachments

  • Capture21.PNG
    Capture21.PNG
    30.5 KB · Views: 2
Hi Deepak

Just have to clear one more point the list of 20 ppl will not be mandatory added in all the mail. Any 2 ppl from the list will communicate with each other and can it also avoid throwing pop-up in such cases as well.

Regards,

JD
 
Hi Deepak

Just have to clear one more point the list of 20 ppl will not be mandatory added in all the mail. Any 2 ppl from the list will communicate with each other and can it also avoid throwing pop-up in such cases as well.

Regards,

JD


Yes, I am working on it
 
JD

Check this pls!!

Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim strSubject As String
Dim StrTo As String
Dim strBody As String
Dim mypeople As Variant, i As Integer, m As Integer

On Error GoTo e
strSubject = Item.Subject
StrTo = Item.To
strBody = Mid(Item.Body, InStr(Item.Body, " ") + 1, InStr(Item.Body, ",") - InStr(Item.Body, " ") - 1)
On Error GoTo 0

mypeople = Array("abc@xyz.com", "abc1@xyz.com", "abc2@xyz.com", "abc3@xyz.com", "abc4@xyz.com", "abc5@xyz.com", "abc6@xyz.com", "abc7@xyz.com", "abc8@xyz.com", "abc9@xyz.com", "abc10@xyz.com", "abc11@xyz.com", "abc12@xyz.com", "abc13@xyz.com", "abc14@xyz.com", "abc15@xyz.com", "abc16@xyz.com", "abc17@xyz.com", "abc18@xyz.com", "abc19@xyz.com", "abc20@xyz.com")

For i = LBound(mypeople) To UBound(mypeople)
    If InStr(LCase(StrTo), mypeople(i)) Then m = m + 1
Next i

If Not m - 1 <> (Len(StrTo) - Len(Replace(StrTo, ";", ""))) Then Exit Sub

Prompt$ = "Verify it " & vbNewLine & "Subject - " & strSubject & vbNewLine & _
            "Mail to - " & StrTo & vbNewLine & _
            "Person - " & strBody & vbNewLine & vbNewLine & "Are you sure you want to send the Mail?"

If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Email Confirmation") = vbNo Then Cancel = True
Exit Sub

e:
Cancel = True
MsgBox "Pls Recheck as per pattern : To[@], Subject[<>], Body[ ,]"
End Sub
 
Hi Deepak

The code is working fine. Thanks for all your help and support on this.

I tested the code with the sample IDs available in the code. It doesn't throw any pop-up msg. I also checked it with my personal ID even that worked fine, but when I am using my official ID which is saved in my outlook with my name

like - Singh, Jagdev <Jagdev.Singh@*****.com>

I tried adding Singh, Jagdev , Jagdev.Singh@*****.com and Singh, Jagdev Jagdev.Singh@*****.com it is throwing the pop-up msg. Could you please lemme know what I am doing wrong here and what should I add in array in such cases.

Regards,
JD
 
Hi Deepak

I have attached the screenshot..

I copied the ID from the outlook it look like - "Sinder, Jagdev <Jagdev.Sinder@******.com>" i have replaced after @ name which is 6 letter word.

Below if the ID I added in the code.

mypeople = Array("Jagdev.Sinder@******.com", "jagdevsingh87@gmail.com", "abc6@xyz.com", "abc7@xyz.com", "abc8@xyz.com", "abc9@xyz.com", "abc10@xyz.com", "abc11@xyz.com", "abc12@xyz.com", "abc13@xyz.com", "abc14@xyz.com", "abc15@xyz.com", "abc16@xyz.com", "abc17@xyz.com", "abc18@xyz.com", "abc19@xyz.com", "abc20@xyz.com")
 

Attachments

  • sample.PNG
    sample.PNG
    20.1 KB · Views: 3
Back
Top