• 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.

Validate To CC address from draft e-mail with FROM address of e-mail body

Status
Not open for further replies.

ThrottleWorks

Excel Ninja
Hi,

I need help for Outlook. We will consider below example.

I have received an e-mail.
In original e-mail. From: is A1@abc.com
In To:
myname@mydomain.com
In CC: manager1@abc.com; manager2@abc.com ; manager3@abc.com
While replying for this e-mail, I have added manager4@abc.com in either To or CC field.
Manager4 was not present in previous e-mail. So I am no supposed to mark him in my reply.

How do I create a macro in excel, which will check To and CC field from open item (draft) against From, To and CC in e-mail body.

Macro should check all the open items which I have replying. For example, there might 10 e-mails open at my system.
And macro should check all the items at one go.

Also, it is possible that there are n number of replies to original e-mail (trail) however I need to reconcile with latest sender details.

Can anyone help me in this please.
 
ThrottleWorks

Your statement is bit confusing.

When replying to all it adds all the recipient in the mail so why need to check them in the body.

So why u need to check -"latest sender details".

When u use the reply to all, very first recipient in To filed is the latest sender.

As
Chihiro said you need to have bit specific about the goal.
 
Hi @Deepak sir, sorry for late reply. Was not able to connect phone net to laptop on weekend hence delay.

Sir, for example you have sent me an e-mail. You have marked no one else.
This is a trail e-mail. May be this was between you, XYZ person and me.

But while replying to you I added Chihiro also.
I am not supposed to add anyone while replying.

So while replying to your e-mail I clicked on 'Reply to All'.
I can see
'Deepak@awesome.com' I also add 'Chihiro@awesome.com' manually.
How do I check this with an excel based macro.

I have code at another machine. Please give me some to share.
Have a nice day ahead.
 
I am able to get To CC and BCC from draft e-mail.
My doubt is, how do I get latest string from From: and Subject: from e-mail body. This will give me latest people marked in e-mail.

Can anyone please help me in this.
 
Are you looking something like this!

Code:
Sub ForaDraftEmail()
Dim myNamespace As NameSpace, myFolder As Folder, myItem As MailItem
Dim strBody As String, strMsg As String, varBody As Variant

Dim iFrom As Integer
Dim iSent As Integer
Dim iTo As Integer
Dim iCc As Integer
Dim iBcc As Integer
Dim iSubject As Integer

Set myNamespace = Application.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderDrafts)
Set myItem = myFolder.Items(1)

strBody = myItem.Body
'Debug.Print strBody

iFrom = InStr(1, strBody, "From:")
iSent = InStr(1, strBody, "Sent:")
iTo = InStr(1, strBody, "To:")
iCc = InStr(1, strBody, "Cc:")
iBcc = InStr(1, strBody, "Bcc:")
iSubject = InStr(1, strBody, "Subject:")

varBody = Split(Mid(strBody, iFrom + 6, iSubject - 8 - 6), vbCr)

strMsg = "Last email details." & vbCr & vbCr & "Sender: " & _
varBody(0) & vbCr & varBody(1) & vbCr & varBody(2)

If iCc > iTo Then
    If iBcc > iCc Then
        strMsg = strMsg & vbCr & Join(Array(varBody(3), varBody(4), vbCr))
    Else
        strMsg = strMsg & vbCr & varBody(3)
    End If
End If

strMsg = strMsg & vbCr & "Subject:" & Split(Mid(strBody, iSubject + 8, 998), vbCr)(0)

MsgBox strMsg

End Sub
 
Hi @Deepak sir, thanks a lot for the help.
I am getting bug at 'Set myNamespace = Application.GetNamespace("MAPI")' line.

I have selected Microsoft Office 14.0 Object library. Could you please help if you get time.
 
Status
Not open for further replies.
Back
Top