Modifying the From Field

T

Tinclon

Help,
I'm designing a custom Message form and I need to change
the From field through a checkbox. Lines such as the
following work no problem:

Item.Subject = "New Subject"
Item.To = "New Recipient"

But this line will not

Item.From = "New Sender"

Why is the From field the only one that doesn't work?

P.S. I've also tried this way,
Item.UserProperties.Find("From").Value = "New Sender"
With no luck.

Thanks,
Tinclon
 
D

Dmitry Streblechenko

You can do that using Extended MAPI/CDO/Redemption, but not Outlook Object
Model. See below for a Redemption example.

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


Is there any way I can select an account to be used for sending a message
with Redemption?
Generally speaking, no. If you look at the message sent using non-default
account using OutlookSpy, you will notice that Outlooks sets a couple of
named properties; one of them is the name of the account, another one is a
combination of the account integer index and its name. The format is not
documented of course.
The good news however is that you can do much better than just selecting an
account: you can set the sender name and address to an arbitrary value, you
do not need to have an account configured with that name and address. The
trick is based on the fact that you can add a named property with a
particular GUID to an outgoing message and force Outlook to use the name of
the property as an RC822 header and its value as the value of the header. By
adding a property with the name "From" and the value in the form "Someone
<[email protected]>" you add an RF822 header:
From: Someone <[email protected]>
Both Exchange and IMAIL providers are smart enough to replace an existing
header if one exists, i.e. you will not get two "From" headers. The only
limitation is that the message must be converted to the RFC822 format along
the way, it will not work if the message is sent between two mailboxes on
the same Exchange server. The message in your Sent Items folder will still
have the default sender name, but the recipients will see the new value.
Whether you use IMAIL (POP3/SMTP) or Exchange provider in Outlook to send a
message, doesn't matter at all, it will work in both cases.
set sItem = CreateObject("Redemption.SafeMailItem")
sItem.Item = MailItem
tag = sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From")
tag = tag or &H1E 'the type is PT_STRING8
sItem.Fields(Tag) = "Someone <[email protected]>"
sItem.Subject = sItem.Subject 'to trick Outlook into thinking that
something has changed
sItem.Save
 

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