How to build Attachments object?

B

Bingo

I have an Outlook MailItem, oMapiMail for an email in the
Inbox. Now I need to build the Attachments object for a
new email based on the Attachments object of oMapiMail.
The following code is able to add the attachments but
they cannot be re-opened. What's the right way to do
this? Thanks.

For Each oMapiRemoteAttachment In
oMapiMail.Attachments
oMapiAttachment.SaveAsFile "c:\1"
Set oMapiAttachmentNew =
oMapiMailNew.Attachments.Add("c:\1",
oMapiAttachment.Type, oMapiAttachment.Position,
oMapiAttachment.DisplayName)
Next
 
B

Bingo

For the "real" attachment, I now use Attachment.FileName
when I save the attachment and then add it to the new
Attachments collection. This type of attachments can now
be opened. But for those OLE objects, it does not allow
me to save to disk and I cannot copy them using
Redemption's SafeMailItem.RTFBody either. Is there a
safe solution to build the Attachments collection to cope
with all types of attachments? Thanks.
 
S

Sue Mosher [MVP-Outlook]

Only by forwarding or copying the complete item. OLE objects cannot be
copied or extracted directly. I think Dmitry has already discussed that with
you.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
B

Bingo

Sue,

The problem for me is that the original mail item is
created on an email from another person's shared folder.
When I apply Forward and ReplyAll, the From is that
person not me. Outlook simply does not allow that. Well
I know on Exchange, I can change the setting to allow set
emails on behalf of somebody else, but it's not a
solution now. That's why I need to rebuild a new mail
item in my local Outlook folder and then copy everything
from the original one. I know this sounds terrible but I
do not really know any other solutions for this. Any
comments? Thanks.
 
S

Sue Mosher [MVP-Outlook]

Have you tried setting the SentOnBehalfOfName property to change the
apparent sender? Or copying the message to your own folder?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
B

Bingo

Sue,

This is getting interesting.

I'm actually trying the SentOnBehalfOfName.

1. I tried to open an email in my own mailbox and create
a new one by applying Forward. Then I set the
SentOnBehalfOfName property to someone else. It's working
in terms of the From is changed to that person.

2. I then tried to open an email from another's shared
folder and create a new one by applying Forward. When I
set the SentOnBehalfOfName property, I'm pretty sure only
the display name changed. The email address is still
another's. Did I miss anything?

Please tell me more about "copying the message to your
own folder." Thanks!
 
S

Sue Mosher [MVP-Outlook]

You didn't say whether you actually sent the messages. That's the only way
to get a real test of the behavior in your particular environment, which
will depend on the permissions the sender has.

You can look up the usage for the Copy method in the object browser and
Help.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
B

Bingo

Sue,

The Copy method copies Sender info as well. No luck
there.

What I really need to do is to replace another person's
name and email with my own name and email as the sender.
In this case, SentOnBehalfOfName is really to send an
email on my own.

Like I said, SentOnBehalfOfName only replace the display
name, not the real email address during the testing.
Thanks.
 
S

Sue Mosher [MVP-Outlook]

In an Exchange environment, SentOnBehalfOfName replaces the actual sender.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
B

Bingo

Sue,

We are on Exchange 2003. Here's the code I'm testing
with. SentOnBehalfOfName only replaces the display
name. I've the permission to access another one's
mailbox on the server. Thanks.

Dim oApp
Dim oNsp
Dim oMapiMail
Dim oMapiMailNew
Dim oMapiInbox
Dim sMailbox

Set oApp = CreateObject("Outlook.Application")
Set oNsp = oApp.GetNamespace("MAPI")
oNsp.Logon "", "", True, True

Set oMapiRecipient = oNsp.CreateRecipient(sMailbox)
Set oMapiInbox = oNsp.GetSharedDefaultFolder
(oMapiRecipient, 6)

Set oMapiMail = oMapiInbox.Items(1)
Set oMapiMailNew = oMapiMail.Forward

oMapiMailNew.SentOnBehalfOfName = "Bingo"
oMapiMailNew.Display

Set oMapiMailNew = Nothing
Set oMapiMail = Nothing

oNsp.LogOff
Set oNsp = Nothing
Set oApp = Nothing
 
D

Dmitry Streblechenko \(MVP\)

Use Safe*Item.CopyTo to copy all message properties, including RTF body and
OLE attachments.

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

Sue Mosher [MVP-Outlook]

Again, what happens when you send the message after changing
SentOnBehalfOfName? Displaying it won't tell you the whole story.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
B

Bingo

Sue,

We gave the permission on the Exchange server to allow me
to send emails out on behalf of another person. So the
email was sent out. I checked the email and
the From is Bingo on behalf of another person.
 
S

Sue Mosher [MVP-Outlook]

That's exactly as it should look if you were given Send On Behalf Of
permission. If instead you were given Send As permission, the From field
would say it's from Bingo.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
B

Bingo

Sue,

I cannot find where to give Send As permission on
Exchange Server. The Send On Behalf is on Delivery
Options window. How do I set up the Send As permission?
Thanks
 
S

Sue Mosher [MVP-Outlook]

It's on the Security tab for the mailbox's AD record.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
B

Bingo

Sue,

Under AD Users and Computers, I opened the properties for
the user. I do not see Security tab. Here are all the
tabs I have:

General
Address
Account
Profile
Telephones
Organization
Email Address
Exchange Features
Exchange Advanced
Terminal Services Profile
Exchange General
Member of
Dial-in
Environment
Sessions
Remote Control

Am I looking at the wrong place? Thanks.
 

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