Macro To Forward Mail Without Security Message (Redemption)

  • Thread starter Thread starter Daniel.Peaper
  • Start date Start date
D

Daniel.Peaper

Hi All,

Can someone help me with, what I'm sure will turn out to be a straight
forward problem? I am trying to send a message to a contact
automatically. For simplicity, as I am learning Outlook VBA, I have
one message in the inbox and one contact.

Using Sue Mosher's excellent book Microsoft outlook Programming I have
arrived at the following code:

Private Sub processMail()
Dim myNS As Outlook.NameSpace
Dim objContacts As Outlook.MAPIFolder
Dim objContact As Outlook.ContactItem
Dim objInbox As Outlook.MAPIFolder
Dim myMessage As Outlook.MailItem
Dim objNewMail As Outlook.MailItem
Dim objSafecontact As Redemption.SafeContactItem
Dim objSafeNewMail As Redemption.SafeMailItem


Set myNS = GetNamespace("MAPI")
Set objContacts = myNS.GetDefaultFolder(olFolderContacts)
Set objContact = objContacts.Items.GetFirst
Set objSafecontact = CreateObject("Redemption.SafeContactItem")
objSafecontact.Item = objContact

Set objInbox = myNS.GetDefaultFolder(olFolderInbox)
Set myMessage = objInbox.Items.GetFirst
Set objNewMail = myMessage.Forward
objNewMail.To = objSafecontact
Set objSafeNewMail = CreateObject("Redemption.SafeMailItem")
objSafeNewMail.Item = objNewMail
objSafeNewMail.Send
End Sub

However, instead of sending my mail it goes into the Drafts Folder and
I cannot figure out why? I might add that the contact that I want to
send it to is a fax recipient but I have tried changing them to an
eMail recipient but it makes no difference - Drafts(1)

I'm running Outlook XP and Redemption 4.4.0.714

Cheers,
Danny
 
The Drafts folder problem is a known issue in Outlook 2002, documented in the Redemption FAQ at http://www.dimastr.com/redemption/faq.htm#1


Also, if you're trying to send a fax, you probably need to change this statement:

objNewMail.To = objSafecontact

to

objNewMail.To = "[FAX:"] & objSafecontact.BusinessFaxNumber & "]"

or whichever fax field holds the number you want to use, so that you can handle cases where the recipient has more than one electronic address or the name is not unique. The FAX: prefix I gave is generic, but might not be the one needed by your specific fax software.
 
Thanks Sue,

That reference helped and my procedure worked okay. I now wish to
modify it to forward each new message that arrives and so I have
included the code in the subroutine m_red_NewMail which I believe
returns the new mail item as an object in its argument. I am using the
following code:

Private Sub m_red_NewMail(ByVal Item As Object)
Dim myNS As Outlook.NameSpace
Dim objContacts As Outlook.MAPIFolder
Dim objContact As Outlook.ContactItem
Dim objNewMail As Outlook.MailItem
Dim objSafecontact As Redemption.SafeContactItem
Dim objSafeNewMail As Redemption.SafeMailItem

Set myNS = GetNamespace("MAPI")
Set objContacts = myNS.GetDefaultFolder(olFolderContacts)
Set objContact = objContacts.Items.GetFirst
Set objSafecontact = CreateObject("Redemption.SafeContactItem")
objSafecontact.Item = objContact
Set objNewMail = Item.Forward

And at the last statement I get an error "object doesn't support this
method"

So, isn't Item an Outlook mailItem object? Obviously it isn't because
it doesn't support the Forward method. In that case how would I go
about forwarding the new message?

Cheers,
Danny...
 
How are you planning to call this procedure? As you've written it, Item is an Object, not a MailItem.
 
Thanks Sue,

That reference helped and my procedure worked okay. I now wish to
modify it to forward each new message that arrives and so I have
included the code in the subroutine m_red_NewMail which I believe
returns the new mail item as an object in its argument. I am using the
following code:

Private Sub m_red_NewMail(ByVal Item As Object)
Dim myNS As Outlook.NameSpace
Dim objContacts As Outlook.MAPIFolder
Dim objContact As Outlook.ContactItem
Dim objNewMail As Outlook.MailItem
Dim objSafecontact As Redemption.SafeContactItem
Dim objSafeNewMail As Redemption.SafeMailItem

Set myNS = GetNamespace("MAPI")
Set objContacts = myNS.GetDefaultFolder(olFolderContacts)
Set objContact = objContacts.Items.GetFirst
Set objSafecontact = CreateObject("Redemption.SafeContactItem")
objSafecontact.Item = objContact
Set objNewMail = Item.Forward

And at the last statement I get an error "object doesn't support this
method"

So, isn't Item an Outlook mailItem object? Obviously it isn't because
it doesn't support the Forward method. In that case how would I go
about forwarding the new message?

Cheers,
Danny...
 
MeetingItem.Forward returns yet another MeetingItem.
ReportItem does not expose the Forward method at all.

Check that Item.Class = 43 before assuming that it is MailItem.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Hi,

I'm expecting the procedure to fire automatically when a new message
arrives which it does. If the Redemption function is returning Item as
an object how can I use that object to reference the mail item and
forward it? Is there a property of the object that I can use to locate
the MailItem in the inbox?

It seems to be inefficient to search through the Inbox when I have
this Item object.

Cheers,
Danny
 
I am not sure I understand what you mean:
If, as you indicated, the line raising the error is ("object doesn't support
this method")
Set objNewMail = Item.Forward
that simply means that whatever the current Item is (ReportItem?) it does
not support the Forward method.

Change your code to

If Item.Class = 43 Then
Set objNewMail = Item.Forward
...

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Okay thanks Dmitry,

I see what you're getting at. Since I'm trying to develop this code,
I'm sending a new message to the inbox and hoping that it gets
forwarded so I wouldn't expect it to be anything other than a mail
item at this stage. If I try it later today and it crashes again I
will see if I can obtain the Item.class value from the immediate
window. Then I'll try your code.

Cheers,
Danny
 
Okay thanks Dmitry,

I see what you're getting at. Since I'm trying to develop this code,
I'm sending a new message to the inbox and hoping that it gets
forwarded so I wouldn't expect it to be anything other than a mail
item at this stage. If I try it later today and it crashes again I
will see if I can obtain the Item.class value from the immediate
window. Then I'll try your code.

Cheers,
Danny

Hi Dmitry,

I tried using your code however, I received the same error. I checked
the class as I said I would and it returned a class of 43. I'm also
able to view properties such as Item.Subject and Item.body.

Cheers,
Danny
 
I now have a working solution to my problem without using the
redemption library. Here is my script that automatically forwards
every new mail to a fax contact:

Private Sub Application_NewMail()
Dim myNS As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myMail As Object
Dim objNewMail As Outlook.MailItem
'
Set myNS = Application.GetNamespace("MAPI")
Set myInbox = myNS.GetDefaultFolder(olFolderInbox)
For Each myMail In myInbox.Items
If myMail.UnRead = True Then
Set objNewMail = myMail.Forward
objNewMail.To = "[Fax:Diner33]"
objNewMail.Send
myMail.UnRead = False
End If
Next
End Sub
 
Back
Top