Adding a recipient from the "ItemSend" event

J

J

Far too frequently I send an e-mail to someone and I forget something,
so I send them another e-mail. I usually go to my sent items folder
and hit "Reply" so that the new e-mail has the old text in it.

When I do this in gmail, it knows I want to send the reply to the
original addressee. When I do this in Outlook 2007, it makes the
reply out to me. This is not desired and it annoys me to have to copy
and paste the text I just wrote into a new, readdressed e-mail.

However, for some reason the e-mail is still addressed to me, BUT gets
sent to the desired recipient with my name in the "To:" field! This
is wierd and this is where I need help.

To test my code you will need someone else you can send e-mails to.
Put this code in, then send them one e-mail, then go to your sent
folder, reply to that message, and hit send to activate my code. It's
wierd! This all boils down to one big question:

1) How do I get it to actually change the text of who it is sending it
to as it sends it?
....with a few side questions if you're feeling extra helpful:
2) How do I reset the Recipients collection so I'm not a part of it
3) Can I get this event to trigger when I first create the reply, not
just at the last minute when I send it?
4) My code is currently in a module(?) called "ThisOutlookSession".
Will this save and work between sessions? If not, will inserting a
new module fix that?


Thank you for your attention and possible help,
~J

Finally my code:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As
Boolean)
On Error GoTo Err_ItemSend
Dim objRecipient As Recipient

'STEP 1. Checks to see if the message is a reply (by seeing if the
subject has "RE:")
'Is there a better way to do this?
If UCase(Left(Item.Subject, 3)) = "RE:" Then

'STEP 2. Checks to see if the recipients are only myself
Dim strRecipients As String
strRecipients = ""

For Each objRecipient In Item.Recipients
strRecipients = strRecipients & objRecipient.Name & ";"
Next

If strRecipients = "MyLastName, MyFirstName;" Then
'Is there a way to not hardcode my name so it works for
anyone?
'STEP 3. Looks up the text of who the message is REALLY to
'is there a better way to do this than searching the body text?
Dim intCursor As Integer
intCursor = InStr(Item.Body, "To: ") + 4
If intCursor <> 4 Then
strRecipients = Mid(Item.Body, intCursor, 20)
intCursor = InStr(strRecipients, vbCr) - 1
If intCursor = 0 Then
strRecipients = InStr(strRecipients, ";") - 1
End If
Debug.Print strRecipients & " : " & intCursor
If intCursor <> 0 Then
strRecipients = Left(strRecipients, intCursor)
Select Case MsgBox("Send message to " & strRecipients & "?",
vbYesNoCancel)
Case vbYes:
'STEP 4. Adds the real recipient to the list
'STEP 5. Continue with the send
Dim objMe As Recipient
Set objMe = Item.Recipients.Add(strRecipients)
objMe.Type = olBCC
objMe.Resolve
Set objMe = Nothing
Case vbNo:
If MsgBox("Send item to yourself?", vbYesNo) = vbNo Then
Cancel = True
Case Else:
Cancel = True
End Select
End If
End If
End If
End If

Exit_ItemSend:
Set objRecipient = Nothing
Exit Sub

Err_ItemSend:
MsgBox "There was an error while checking if your e-mail was a
reply to yourself." & vbCr & Err.Number & " - " & Err.Description
Resume Exit_ItemSend
End Sub
 
S

Sue Mosher [MVP-Outlook]

I usually just use Reply to All and delete my own address (or not, as I'm inclined). THe code you have below is not guaranteed to work because there's no way to be sure that the other person's address is anywhere in the reply message.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top