Redemption/Outlook cant set recipient types!!


A

amarmaj

Somebody please indulge me! I'm tearing my hair out at trying to set
the TO and CC recipient types using the function below.

If I have just one name in the TO and one in the CC all works well.
However if I have multiple entries in the CC field (passed in as a ;
separated list), when the mail is received by the various recipients,
the TO and CC are all messed up and not as in the TO and CC fields as I
had sent them.

I've tried various ways of setting the TO and CC types eg
SafeItem.Recipients.Item(0).Type = SafeItem.Recipients.Item(0).Type
= olCC
' SafeItem.Recipients.Item(0).Type =
Outlook.OlMailRecipientType.olCC
' SafeItem.Recipients.Item(0).Type = olCC

but to no joy. I'm sure I am probably missing something quite simple.

ps using Outlook 2003 on Win XP Pro SP2

thanks for any help
Amar

Function SendSafeMail(sTO As String, sSubject As String, sBody As
String, Optional sAttachment As String, Optional sCC As String) As
Boolean
'******************************************************
'Name: SendSafeMail
'
'Purpose: Sends email. Uses Outlook application to login to default
profile,
' then uses Redemption to send mail in order to avoid
' Oulook security prompts
'
'Inputs: to,subject,body,attachment,cc
'
'Returns: boolean
'**********************************************************

On Error GoTo ErrHandler

Dim ouApp As Outlook.Application
Dim ouNS As Outlook.NameSpace
Dim SafeItem As Redemption.SafeMailItem
Dim oItem As Object
Dim arrTORecipients() As String
Dim arrCCRecipients() As String
Dim i As Integer

Set ouApp = CreateObject("Outlook.Application")
Set ouNS = ouApp.GetNamespace("MAPI")
ouNS.Logon 'login using default user credentials

Set SafeItem = CreateObject("Redemption.SafeMailItem")
Set oItem = ouApp.CreateItem(0) 'new message

SafeItem.Item = oItem
SafeItem.Subject = sSubject
SafeItem.Body = sBody

If Len(sAttachment) <> 0 Then
SafeItem.Attachments.Add (sAttachment)
End If


'see if there is more than one TO recipient
If InStr(1, sTO, ";") > 0 Then
arrTORecipients() = Split(sTO, ";")
For i = 0 To UBound(arrTORecipients)
'add all the recipients to TO list
SafeItem.Item = oItem
SafeItem.Recipients.Add arrTORecipients(i)
SafeItem.Recipients.Item(0).Type =
SafeItem.Recipients.Item(0).Type = olTO
'SafeItem.Recipients.Item(0).Type =
Outlook.OlMailRecipientType.olTO
'SafeItem.Recipients.Item(0).Type = olTO
Next i
Else
'just one recipient
SafeItem.Item = oItem
SafeItem.Recipients.Add (sTO)
SafeItem.Recipients.Item(0).Type =
SafeItem.Recipients.Item(0).Type = olTO
'SafeItem.Recipients.Item(0).Type =
Outlook.OlMailRecipientType.olTO
'SafeItem.Recipients.Item(0).Type = olTO
End If

If Len(sCC) <> 0 Then
'see if there is more than one CC
If InStr(1, sCC, ";") > 0 Then
arrCCRecipients() = Split(sCC, ";")
For i = 0 To UBound(arrCCRecipients)
'add all the recipients to TO list
SafeItem.Item = oItem
SafeItem.Recipients.Add arrCCRecipients(i)
SafeItem.Recipients.Item(0).Type =
SafeItem.Recipients.Item(0).Type = olCC
' SafeItem.Recipients.Item(0).Type =
Outlook.OlMailRecipientType.olCC
' SafeItem.Recipients.Item(0).Type = olCC
Next i
Else
SafeItem.Item = oItem
SafeItem.Recipients.Add (sCC)
SafeItem.Recipients.Item(0).Type =
SafeItem.Recipients.Item(0).Type = olCC
' SafeItem.Recipients.Item(0).Type =
Outlook.OlMailRecipientType.olCC
' SafeItem.Recipients.Item(0).Type = olCC
End If
End If

SafeItem.Recipients.ResolveAll


SafeItem.Send
SendSafeMail = True
ExitPoint:
On Error Resume Next
Set ouApp = Nothing
Set ouNS = Nothing
Set oItem = Nothing
Set SafeItem = Nothing
Exit Function

ErrHandler:
SendSafeMail = False
Resume ExitPoint
End Function
 
Ad

Advertisements

D

Dmitry Streblechenko

1.Recipients collection is 1 based, not 0.

2. Why do you keep resetting the type of the recipient #0 (which is supposed
to be 1 I guess)? Since you just called Add, the index will be either i+1
(since i is 0 based) or Recipients.Count (the last recipient in the
collection). Or you can simply take advantage of the fact that
Recipients.Add returns a Recipient object

set Recip = SafeItem.Recipients.Add(arrCCRecipients(i))
Recip.Type = olCC

3. I am not sure what the next line is supposed to do.

SafeItem.Recipients.Item(0).Type = SafeItem.Recipients.Item(0).Type = olCC

You are setting a property of type integer (Type) to as boolean variable;
that's what you code translates to:

bool = SafeItem.Recipients.Item(0).Type = olCC
SafeItem.Recipients.Item(0).Type = bool


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

Advertisements

A

amarmaj

Dimitry,

What more can I say but thankyou. It all works fine now :)

ps
SafeItem.Recipients.Item(0).Type = SafeItem.Recipients.Item(0).Type =
olCC

this was me just getting desperate and trying various things, wasnt
aware of the data types cleary!! (a little knowledge can be very bad
for you)
 

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