Discussion:
attachment location
(too old to reply)
sophie
2008-10-08 09:19:01 UTC
Permalink
hi, all

I am working on attachment. I don't know how to get the location of a
sending email' attachment.

I want to do some operation before the email be sent.

is "Source Property" works? but when i use it like this
"objMailItem.attachments.Source" or "objMailItem.attachments.item(1).source",
it seems wrong.

pathName property seem work, but when i check the mail attachment item,
pathName is null.

i need help.

thanks.
Sue Mosher [MVP-Outlook]
2008-10-08 12:38:01 UTC
Permalink
A file attached to a message is contained in that message, in the Attachments
collection. Outlook neither knows nor cares about the original location of
the file, which may no longer even exist.

If you want to do some work on that file, you need to save it to the local
drive using the Attachment.SaveAsFile method. You can then modify the file,
remove the original attachment, and add the new version.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Post by sophie
hi, all
I am working on attachment. I don't know how to get the location of a
sending email' attachment.
I want to do some operation before the email be sent.
is "Source Property" works? but when i use it like this
"objMailItem.attachments.Source" or "objMailItem.attachments.item(1).source",
it seems wrong.
pathName property seem work, but when i check the mail attachment item,
pathName is null.
i need help.
thanks.
sophie
2008-10-09 02:20:01 UTC
Permalink
Thanks sue.
I will try in this way.
Post by Sue Mosher [MVP-Outlook]
A file attached to a message is contained in that message, in the Attachments
collection. Outlook neither knows nor cares about the original location of
the file, which may no longer even exist.
If you want to do some work on that file, you need to save it to the local
drive using the Attachment.SaveAsFile method. You can then modify the file,
remove the original attachment, and add the new version.
--
Sue Mosher, Outlook MVP
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Post by sophie
hi, all
I am working on attachment. I don't know how to get the location of a
sending email' attachment.
I want to do some operation before the email be sent.
is "Source Property" works? but when i use it like this
"objMailItem.attachments.Source" or "objMailItem.attachments.item(1).source",
it seems wrong.
pathName property seem work, but when i check the mail attachment item,
pathName is null.
i need help.
thanks.
khai
2009-01-07 03:23:01 UTC
Permalink
Hi Sue,

The SaveAsFile method works for normail emails. However, when I try to
execute this method on inline attachments (namely, images), I get the
following error:

"Cannot save the attachment. Cannot add the attachment; no data source was
provided."

Could you shed some light on why this is so, and how can I overcome it? Many
thanks in advance.
Post by Sue Mosher [MVP-Outlook]
A file attached to a message is contained in that message, in the Attachments
collection. Outlook neither knows nor cares about the original location of
the file, which may no longer even exist.
If you want to do some work on that file, you need to save it to the local
drive using the Attachment.SaveAsFile method. You can then modify the file,
remove the original attachment, and add the new version.
--
Sue Mosher, Outlook MVP
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Post by sophie
hi, all
I am working on attachment. I don't know how to get the location of a
sending email' attachment.
I want to do some operation before the email be sent.
is "Source Property" works? but when i use it like this
"objMailItem.attachments.Source" or "objMailItem.attachments.item(1).source",
it seems wrong.
pathName property seem work, but when i check the mail attachment item,
pathName is null.
i need help.
thanks.
Ken Slovak - [MVP - Outlook]
2009-01-07 14:20:27 UTC
Permalink
Sue's not available.

In that case there is nothing to go on for Outlook and most likely the
Attachment fields such as PR_ATTACH_FILENAME and such are blank. Are these
images or embedded Outlook objects? In any case about all you could do on a
low level would be to try to extract the attachment binary data and save
that out but you wouldn't know the file type or correct file format so that
wouldn't do much good at all.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by khai
Hi Sue,
The SaveAsFile method works for normail emails. However, when I try to
execute this method on inline attachments (namely, images), I get the
"Cannot save the attachment. Cannot add the attachment; no data source was
provided."
Could you shed some light on why this is so, and how can I overcome it? Many
thanks in advance.
khai
2009-01-09 10:53:01 UTC
Permalink
They are actually inline images. When I try to get the Type, it returns
olByValue.

I realise that I encounter this problem if I use Word 2003 to edit the email
messages (i.e. checkbox found under Tools -> Options -> Mail Format ->
Message Format).

Is there a work around, to ensure that inline images will be saved correctly
even if Word 2003 is chosen as the editor?
Post by Ken Slovak - [MVP - Outlook]
Sue's not available.
In that case there is nothing to go on for Outlook and most likely the
Attachment fields such as PR_ATTACH_FILENAME and such are blank. Are these
images or embedded Outlook objects? In any case about all you could do on a
low level would be to try to extract the attachment binary data and save
that out but you wouldn't know the file type or correct file format so that
wouldn't do much good at all.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by khai
Hi Sue,
The SaveAsFile method works for normail emails. However, when I try to
execute this method on inline attachments (namely, images), I get the
"Cannot save the attachment. Cannot add the attachment; no data source was
provided."
Could you shed some light on why this is so, and how can I overcome it? Many
thanks in advance.
Ken Slovak - [MVP - Outlook]
2009-01-09 14:36:54 UTC
Permalink
Not really other than not using inline images.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by khai
They are actually inline images. When I try to get the Type, it returns
olByValue.
I realise that I encounter this problem if I use Word 2003 to edit the email
messages (i.e. checkbox found under Tools -> Options -> Mail Format ->
Message Format).
Is there a work around, to ensure that inline images will be saved correctly
even if Word 2003 is chosen as the editor?
khai
2009-02-05 07:42:03 UTC
Permalink
Im still stuck on this problem. It is definitely not possible to force users
to not use inline images as it would be an "un-friendly restriction" to
impose on the users.

I have found out that if Word is being used as the editor, the filename of
the attachment is automatically converted to something else i.e.
image001.jpg, as compared to the actual name of the file when Word is not
being used as the editor. Could this be the reason why the "Cannot save
attachment. Cannot add attachment; no data source was provided" error was
returned?
Post by Ken Slovak - [MVP - Outlook]
Not really other than not using inline images.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by khai
They are actually inline images. When I try to get the Type, it returns
olByValue.
I realise that I encounter this problem if I use Word 2003 to edit the email
messages (i.e. checkbox found under Tools -> Options -> Mail Format ->
Message Format).
Is there a work around, to ensure that inline images will be saved correctly
even if Word 2003 is chosen as the editor?
Ken Slovak - [MVP - Outlook]
2009-02-05 14:56:16 UTC
Permalink
Using the Outlook object model, except in Outlook 2007, won't allow you to
do what you want. Even in Outlook 2007 if the data for the image is larger
than about 8KB you can't do what you want. You would need to use a lower
level API such as Extended MAPI (C++ or Delphi only), or a MAPI wrapper such
as Redemption (www.dimastr.com/redemption).

If you use a lower level API you can get the attachments collection, which
includes those embedded images. In that case you can get the attachment
property PR_ATTACH_MIME_TAG and read something like "image/jpeg" and the
property PR_ATTACH_EXTENSION and see something like ".jpg". You can use
those to identify the image type. The file name is changed and you can't do
anything about that. It will be something like PR_ATTACH_FILENAME =
"image001.jpg". Once the image is embedded it loses all connection to the
original image file.

Then you'd get the binary data for the image file using the PT_BINARY
property PR_ATTACH_DATA_BIN and read that array of bytes and save the byte
array out to the file system with the name you got from PR_ATTACH_FILENAME.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by khai
Im still stuck on this problem. It is definitely not possible to force users
to not use inline images as it would be an "un-friendly restriction" to
impose on the users.
I have found out that if Word is being used as the editor, the filename of
the attachment is automatically converted to something else i.e.
image001.jpg, as compared to the actual name of the file when Word is not
being used as the editor. Could this be the reason why the "Cannot save
attachment. Cannot add attachment; no data source was provided" error was
returned?
khai
2009-02-09 02:35:01 UTC
Permalink
Hi,

How exactly can I use the lower API method to get those properties?
Is there a reference you can suggest?
Post by Ken Slovak - [MVP - Outlook]
Using the Outlook object model, except in Outlook 2007, won't allow you to
do what you want. Even in Outlook 2007 if the data for the image is larger
than about 8KB you can't do what you want. You would need to use a lower
level API such as Extended MAPI (C++ or Delphi only), or a MAPI wrapper such
as Redemption (www.dimastr.com/redemption).
If you use a lower level API you can get the attachments collection, which
includes those embedded images. In that case you can get the attachment
property PR_ATTACH_MIME_TAG and read something like "image/jpeg" and the
property PR_ATTACH_EXTENSION and see something like ".jpg". You can use
those to identify the image type. The file name is changed and you can't do
anything about that. It will be something like PR_ATTACH_FILENAME =
"image001.jpg". Once the image is embedded it loses all connection to the
original image file.
Then you'd get the binary data for the image file using the PT_BINARY
property PR_ATTACH_DATA_BIN and read that array of bytes and save the byte
array out to the file system with the name you got from PR_ATTACH_FILENAME.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by khai
Im still stuck on this problem. It is definitely not possible to force users
to not use inline images as it would be an "un-friendly restriction" to
impose on the users.
I have found out that if Word is being used as the editor, the filename of
the attachment is automatically converted to something else i.e.
image001.jpg, as compared to the actual name of the file when Word is not
being used as the editor. Could this be the reason why the "Cannot save
attachment. Cannot add attachment; no data source was provided" error was
returned?
Ken Slovak - [MVP - Outlook]
2009-02-09 14:07:09 UTC
Permalink
That depends on what you plan to use. Google is your friend.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by khai
Hi,
How exactly can I use the lower API method to get those properties?
Is there a reference you can suggest?
leigh
2013-07-05 14:55:12 UTC
Permalink
khai wrote on 01/06/2009 22:23 ET
Post by khai
Hi Sue
The SaveAsFile method works for normail emails. However, when I try t
execute this method on inline attachments (namely, images), I get th
following error
"Cannot save the attachment. Cannot add the attachment; no data source wa
provided.
Could you shed some light on why this is so, and how can I overcome it? Man
thanks in advance
Post by Sue Mosher [MVP-Outlook]
A file attached to a message is contained in that message, in the Attachment
collection. Outlook neither knows nor cares about the original location o
the file, which may no longer even exist
If you want to do some work on that file, you need to save it to the loca
drive using the Attachment.SaveAsFile method. You can then modify the file
remove the original attachment, and add the new version
Sue Mosher, Outlook MV
Author of Microsoft Outlook 2007 Programming
Jumpstart for Power Users and Administrator
http://www.outlookcode.com/article.aspx?id
Post by sophie
hi, al
I am working on attachment. I don't know how to get the location of
sending email' attachment
I want to do some operation before the email be sent
is "Source Property" works? but when i use it like thi
"objMailItem.attachments.Source" o
"objMailItem.attachments.item(1).source"
Post by sophie
it seems wrong
pathName property seem work, but when i check the mail attachment item
pathName is null
i need help
thanks
Hi Khai
I have the same problem and found this work around
Tr
emailAttachments.Item(i).SaveAsFile(strFile
Catch ex As COMExceptio
MsgBox(ex.Message
End Tr

The catch allowed the loop through the email attachments to continue and th
file (signature image) that was causing the problem ended up being saved.
Loading...