Automating Outlook 2003

A

Andrew Kennard

Hi all

Please can someone tell me if the following is possible :-

I would like to automate Outlook 2003 (and beyond) using the ocx/object
model interface from another application

These are the kind of things I would like to be able to do

1) Fire up the new message dialogue with the To field completed by the
calling program. The user then complete a HTML message using all the outlook
features and clicks send. I would then like the calling app to get an ID
back so that I could then reopen the message from Sent Items etc at a later
time

2) I would also like to be able to do personalised 'bulk' emails where the
body has specific information from the calling app unique to each record
message. ie a mailmerge type email run where every message is in effect
unique. Is it passible for the user to setup the message in say the drafts
folder with [Title] [Forename] [Surname] type markers and then an external
application be able to read the HTML body of the message make the necessary
subsititions and then sned a new message back to outlook for it to send. The
reason I want to take this sort of approach is that I want to use the power
of outlooks HTML message creation but need to be able to tightly controll it
from my own app so data from database records can be used to create
individual messages and also as each message is sent I want to be able to
mark each database record with date/time stamp as it goes

There are masses of OCX's out there that will do SMTP mail sending etc there
are also HTML editor OCX's that are designed for web page creation. BUT I
cannot find anywhere something that will create a proper HTML message and
send it ..... other than outlook.

Hoping someone else has been here before where they want good quality
flexible (ie not just 'fixed' invoices/statements etc) HTML email
integration embedded into their own software

Thanks in advance

Andrew
 
K

Ken Slovak - [MVP - Outlook]

You can create a new message and add recipients to it. You might hit the
Outlook security depending on what code you write. The EntryID of the email
(GUID) may change when it's moved to Sent Items after sending, but you can
handle the ItemAdd event for the Items collection of the Sent Items folder
to know what was added when and match subjects.

You can certainly use replacement fields within HTML and replace them with
specific information of your choosing. I recently wrote an addin for a hotel
company that did exactly that.

However, be aware that Outlook may rearrange your HTML as the message is
being sent, plus if WordMail used the rearrangement will be even worse. So
do not depend on maintaining your exact HTML formatting or being able to
deconstruct the HTML in Sent Items or at the recipient and have it end up as
exactly the same HTML that was originally created. WordMail is notorious for
adding all sorts of real ugly HTML to your message and drastically
rearranging or rewriting HTML tags.




Andrew Kennard said:
Hi all

Please can someone tell me if the following is possible :-

I would like to automate Outlook 2003 (and beyond) using the ocx/object
model interface from another application

These are the kind of things I would like to be able to do

1) Fire up the new message dialogue with the To field completed by the
calling program. The user then complete a HTML message using all the
outlook features and clicks send. I would then like the calling app to get
an ID back so that I could then reopen the message from Sent Items etc at
a later time

2) I would also like to be able to do personalised 'bulk' emails where the
body has specific information from the calling app unique to each record
message. ie a mailmerge type email run where every message is in effect
unique. Is it passible for the user to setup the message in say the drafts
folder with [Title] [Forename] [Surname] type markers and then an external
application be able to read the HTML body of the message make the
necessary subsititions and then sned a new message back to outlook for it
to send. The reason I want to take this sort of approach is that I want to
use the power of outlooks HTML message creation but need to be able to
tightly controll it from my own app so data from database records can be
used to create individual messages and also as each message is sent I want
to be able to mark each database record with date/time stamp as it goes

There are masses of OCX's out there that will do SMTP mail sending etc
there are also HTML editor OCX's that are designed for web page creation.
BUT I cannot find anywhere something that will create a proper HTML
message and send it ..... other than outlook.

Hoping someone else has been here before where they want good quality
flexible (ie not just 'fixed' invoices/statements etc) HTML email
integration embedded into their own software

Thanks in advance

Andrew
 
A

Andrew Kennard

Ken

Thanks for your reply

I've had a look on outlookcode.com but couldn;t really see anything on there
for what I wanted (could have missed it)

Had a glance at the outlook object model on msdn but again could not see any
samples in the area I was looking

One significant point to what i'm try to do is that every message will be
UNIQUE whether it be a "one off" or a "run" ie it will only ever have one
receipient and the content will be personalises to that individual.

The GUID for acessing the message sound hopefull as it would be really nice
to be able to keep an email history for a person in the main system and be
able to 'pull up' previously sent messages to that person etc etc

Could you point me to any resources to get me started ? I sounds like you
have been doing something similar

Cheers

Andrew

Ken Slovak - said:
You can create a new message and add recipients to it. You might hit the
Outlook security depending on what code you write. The EntryID of the
email (GUID) may change when it's moved to Sent Items after sending, but
you can handle the ItemAdd event for the Items collection of the Sent
Items folder to know what was added when and match subjects.

You can certainly use replacement fields within HTML and replace them with
specific information of your choosing. I recently wrote an addin for a
hotel company that did exactly that.

However, be aware that Outlook may rearrange your HTML as the message is
being sent, plus if WordMail used the rearrangement will be even worse. So
do not depend on maintaining your exact HTML formatting or being able to
deconstruct the HTML in Sent Items or at the recipient and have it end up
as exactly the same HTML that was originally created. WordMail is
notorious for adding all sorts of real ugly HTML to your message and
drastically rearranging or rewriting HTML tags.




Andrew Kennard said:
Hi all

Please can someone tell me if the following is possible :-

I would like to automate Outlook 2003 (and beyond) using the ocx/object
model interface from another application

These are the kind of things I would like to be able to do

1) Fire up the new message dialogue with the To field completed by the
calling program. The user then complete a HTML message using all the
outlook features and clicks send. I would then like the calling app to
get an ID back so that I could then reopen the message from Sent Items
etc at a later time

2) I would also like to be able to do personalised 'bulk' emails where
the body has specific information from the calling app unique to each
record message. ie a mailmerge type email run where every message is in
effect unique. Is it passible for the user to setup the message in say
the drafts folder with [Title] [Forename] [Surname] type markers and then
an external application be able to read the HTML body of the message make
the necessary subsititions and then sned a new message back to outlook
for it to send. The reason I want to take this sort of approach is that I
want to use the power of outlooks HTML message creation but need to be
able to tightly controll it from my own app so data from database records
can be used to create individual messages and also as each message is
sent I want to be able to mark each database record with date/time stamp
as it goes

There are masses of OCX's out there that will do SMTP mail sending etc
there are also HTML editor OCX's that are designed for web page creation.
BUT I cannot find anywhere something that will create a proper HTML
message and send it ..... other than outlook.

Hoping someone else has been here before where they want good quality
flexible (ie not just 'fixed' invoices/statements etc) HTML email
integration embedded into their own software

Thanks in advance

Andrew
 
K

Ken Slovak - [MVP - Outlook]

For personalizing each email from replacement fields, that's all slog work.
You read HTMLBody of an email and use that string to look for your
replacement fields. Then you just replace the token with the specific data.

To add a recipient to an email just get its Recipients collection and use
the Add method to add the recipient and resolve it.

Be aware that using the Outlook object model in this way from an external
application will cause security prompts in Outlook 2003. For example,
reading of HTMLBody will do that. That would not happen in an Outlook COM
addin. To avoid the prompts you would need to use an Extended MAPI wrapper
such as Redemption (www.dimastr.com/redemption).

Outlook 2007 is better with external applications, if your A-V is up to date
it will permit otherwise blocked accesses.

Again, a source of lots of code samples is outlookcode.com. What you want to
do will incorporate lots of different techniques, so I can't just point at
one sample. But with so much there you will find relevant code samples for
whatever language you plan to program in.

If you want a related emails record for a specific contact you can manually
or in code add the contact object to the Contacts area of an email (in the
Options dialog) or using code add it to the Links collection and new Link.
Then in the UI you can go to the Activities tab of the contact item and see
all related correspondence, tasks, appointments, etc. for that contact.
 
A

Andrew Kennard

Ken

Thanks for your prompt reply.

I've ordered the Outlook code book and shall have a proper look at it soon

Thanks again

Andrew
 

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