use of Redemption in sceduled Task

  • Thread starter Thread starter jpfi
  • Start date Start date
J

jpfi

Hi,

I've written an console-application based on Redemption
(http://www.dimastr.com/redemption/)).
the following code tries to resolve the smtp-Address of the mailsender:

if(addressEntry.Type.Equals("EX")){
//39FE = PR_SMTP_ADDRESS 001E for type PT_String8
String temp = (String)addressEntry.get_Fields(0x39FE001E);
if(temp == null){
//403E = PR_OrgEmailAddr 001E for type PT_String8
temp = (String)addressEntry.get_Fields(0x403E001E);
if(temp==null){
throw new
Exceptions.MailAddressCouldNotExtractedException(addressEntry.Address);
}
}
return temp;
}

In case of starting the application in normal way the shown code works.
addressEntry.get_Fields(0x39FE001E) return the correct value.
When handling the same mail by starting the app per sceduled task (same
user performer) addressEntry.get_Fields(0x39FE001E) return null !

any idea?
Thank you,

Jan
 
Are you using a Redemption RDOSession object or what? You don't show enough
of your code to tell.

Generally if the user has started Outlook and you piggy-back on that session
you're all logged in. If Outlook is started using automation you either have
to log onto an RDOSession or if you're deriving things from NameSpace you
need to logon to the NameSpace before anything else and then make sure you
assign the NameSpace.MAPIOBJECT to the Redemption object's MAPIOBJECT.
 
Hi,

thanks Ken. I think my logon works correctly, because I can read the
mail-properties of mails sent by smtp-mailaccounts. But I cannot read
some mail-properties of mails sent by an exchange-account, e.g.
addressEntry.Type ist null.
It seems to me, that something around the addressbook doesn't work.

A little bit in detail:

I configure a scheduled task with username and password and my exe.
This user has a configured outlook-profile.

some code snippets:
//main-method opens outlook-App
Application outLookApp = new Application();

/* ...
* find correct MAPIFolder...
* get items of MAPIFolder...
* for each item get recipients an extract smtp-address--> call
extractTo(mailItem.Recipients)
* for each item get Sender an extract smtp-address--> call
extractMailAddress(mailItem.Sender)
*/

private StringCollection extractTo(SafeRecipients recipients){
System.Collections.IEnumerator enumerator =
recipients.GetEnumerator();
StringCollection list = new StringCollection();
while(enumerator.MoveNext()){
SafeRecipient recipient = (SafeRecipient)enumerator.Current;
if(OlMailRecipientType.olTo.GetHashCode() == recipient.Type)
list.Add(extractMailAddress(recipient.AddressEntry));
}
return list;
}

private String extractMailAddress(Redemption.AddressEntry
addressEntry){
String temp;
if(addressEntry.Type!=null && addressEntry.Type.Equals("EX")){
//39FE = PR_SMTP_ADDRESS 001E for type PT_String8
temp = (String)addressEntry.get_Fields(0x39FE001E);
if(temp == null){
//403E = PR_OrgEmailAddr 001E for type PT_String8
temp = (String)addressEntry.get_Fields(0x403E001E);
if(temp==null){
throw new
Exceptions.MailAddressCouldNotExtractedException(addressEntry.Address);
}
}
}
else{
temp = addressEntry.Address;
}
log.Debug("Address found: "+temp);
return temp;
}

jpfi
 
Hi,

I tried the same thing with RDO as workaround.
SMTPAddress of RDOAdressEntry works correctly, also within a scheduled
task.

jpfi
 
Note that the scheduler runs as a service, and no Office app should be used
in a service.
Most likely Redemption cannot automatically pick up the MAPI session used by
Outlook, you can help it by calling something like the following first :

set Utils = CreateObject("Redemption.MAPIUtils")
Utils.MAPIOBJECT = YourOutlookApp.Session.MAPIOBJECT
'your old Redemption code goes here.

Thiswill ensure that Redemption caches teh MAPI session used by Outlook.
Or use the RDO family of objects...

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Hi,
I've tried setting the MAPIOBJECT, but it doesn't work.
but

Application outLookApp = new Application();
Redemption.RDOSession session =
(Redemption.RDOSession)outLookApp.CreateObject("Redemption.RDOSession");
session.MAPIOBJECT = outLookApp.Session.MAPIOBJECT;
RDOAddressEntry entry =
session.GetAddressEntryFromID(addressEntry.ID,null);
String smtp = entry.SMTPAddress;

works in all cases.

I still don't figure out why using the other code...
@Dimitry: Thanks for your great Utilities. My company just purchased a
license! Well done.

cheers, jan
 

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

Back
Top