PDA

View Full Version : Forward an email



kbsudhir
10-09-2008, 02:18 PM
Hi All,

I am trying to forward the mails in inbox which are more than 2hrs old.

Below is the code which I thought of but teh problem is sometimes it seems to work & most of the times is do not work. I am forwarding the mails to three persons.

Please let me know where I am going wrong.


Sub ForwardMails()
On Error Resume Next

Dim Fld_Path As Object
Dim Item As Object
Dim myattachments As Outlook.Attachments

'Set Fld_Path = Application.GetNamespace("MAPI").Folders("Mailbox - Mine").Folders("Inbox")

Dim CurrTme, RecTme As Date
Dim TmeDiff As Integer
CurrTme = Format(Now, "[$-409]m/d/yy h:mm AM/PM;@")
For Each Item In Fld_Path.Items

TmeDiff = DateDiff("H", Item.ReceivedTime, CurrTme)
If TmeDiff >= 2 Then
Set myattachments = Item.Attachments
If myattachments.Count > 0 Then

'
Set MyItem = Item.Forward
MyItem.Body = "This mail is in the assigned folder for more than 2Hrs"
MyItem.Recipients.add "Person1; Person2; Person3"
MyItem.Send

End If
End If
Next Item
End Sub



:doh: :doh:
Sudhir

kbsudhir
10-09-2008, 02:24 PM
I am getting the error in this line
MyItem.Recipients.add "Person1; Person2; Person3"

My question is can't we give three persons name as Recipients as we do manually in VBA then how..??

Demosthine
10-09-2008, 03:42 PM
Afternoon there.

I am assuming you are connecting to an Exchange Server and you want to be able to send the To Property values like "Sweeney Todd" or "Jolly Roger" and have them evaluate to "S_Todd@Broadway.Com" and "J_Roger@Sea.Com".

To do this, add one recipient at a time and then Resolve the address. If it resolves, simply send the email; otherwise, have additional processing.


Dim intPerson as Integer
Dim strPersons() as String

strPersons = Array("Sweeney Todd", "Jolly Roger")

For intPerson = 1 to UBound(strPersons)
With MyItem.Recipients
.Add strPersons(intPerson)
If Not .Resolve Then
' Name did not resolve correctly, process for error.
End if
End With
Next intPerson


Scott