Adding attachment in Outlook: Can this be done? 
Author Message
 Adding attachment in Outlook: Can this be done?

I have been searching google for hours now and there are no examples
out there.

Here is my code so far: (it works by the way)

Outlook.Application oApp = new Outlook.Application();
Outlook._NameSpace oNameSpace =  oApp.GetNamespace("MAPI");
Outlook.MAPIFolder oSentFolder;
Outlook._MailItem oMailItem =
(Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oSentFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);


oMailItem.Subject = "Client Server Program Test";
oMailItem.Body = "This is a test of the body part";

--The following is the line that I cannot get to work.

oMailItem.SaveSentMessageFolder = oSentFolder;
oMailItem.Send();

The following is the definition for the add procedure.
I cannot figure out what it wants when it says "object source, object
type", etc, etc..

Attachment.Add(Object Source,Object Type, Object Position,
System.Object DisplayName)

Any ideas would be great, thanks for your help.



Mon, 01 Aug 2005 04:26:17 GMT  
 Adding attachment in Outlook: Can this be done?


Quote:
> I have been searching google for hours now and there are no examples
> out there.

> Here is my code so far: (it works by the way)

> Outlook.Application oApp = new Outlook.Application();
> Outlook._NameSpace oNameSpace =  oApp.GetNamespace("MAPI");
> Outlook.MAPIFolder oSentFolder;
> Outlook._MailItem oMailItem =
> (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
> oSentFolder =

oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);

Quote:


> oMailItem.Subject = "Client Server Program Test";
> oMailItem.Body = "This is a test of the body part";

> --The following is the line that I cannot get to work.

> oMailItem.SaveSentMessageFolder = oSentFolder;
> oMailItem.Send();

> The following is the definition for the add procedure.
> I cannot figure out what it wants when it says "object source, object
> type", etc, etc..

> Attachment.Add(Object Source,Object Type, Object Position,
> System.Object DisplayName)

> Any ideas would be great, thanks for your help.

Try this:

oMailItem.Save
oMailItem.Attachments.Add(filetoattach, olByValue)

olByValue indicates to embed the attachment into the email.  I'm not sure
why it needs to be saved first, but that's what I've done in my (long
untouched) code and I'm sure I had a very good reason at the time.

Mark



Mon, 01 Aug 2005 05:31:08 GMT  
 Adding attachment in Outlook: Can this be done?
The mapi attachment source is the location of  the named file.  Suppose, for
example, I had an image on drive C

Attachments,add( "C:\MyAttachment.jpg")

That's as simple as it gets.  But if you really want to get {*filter*} with
this, you can specify an OLEtype with a type constant for the second
variable and then specify the roder in which this newly assigned attachment
is listed.

If you run the object browser, you'll find these types under
olAttachmentType

There's four of them:

olByReference = 4
olByValue =1
olEmbededItem =5
olOLE =6

A good source is:

http://www.*-*-*.com/

hth


Quote:
> I have been searching google for hours now and there are no examples
> out there.

> Here is my code so far: (it works by the way)

> Outlook.Application oApp = new Outlook.Application();
> Outlook._NameSpace oNameSpace =  oApp.GetNamespace("MAPI");
> Outlook.MAPIFolder oSentFolder;
> Outlook._MailItem oMailItem =
> (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
> oSentFolder =

oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
Quote:


> oMailItem.Subject = "Client Server Program Test";
> oMailItem.Body = "This is a test of the body part";

> --The following is the line that I cannot get to work.

> oMailItem.SaveSentMessageFolder = oSentFolder;
> oMailItem.Send();

> The following is the definition for the add procedure.
> I cannot figure out what it wants when it says "object source, object
> type", etc, etc..

> Attachment.Add(Object Source,Object Type, Object Position,
> System.Object DisplayName)

> Any ideas would be great, thanks for your help.



Mon, 01 Aug 2005 05:32:20 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Outlook MailItem.Attachments.Add method, Position Parameter

2. Adding an OLE attachment to an Outlook item

3. Add attachments linked to elements of the outlook folder system

4. I want to add attachments to emails in outlook

5. Outlook MailItem.Attachments.Add method, Position Parameter

6. add name of attachment to Subject line and delete attachment

7. Accept drops of messages from Outlook and Dragging attachments from MS Outlook

8. Accept drops of messages from Outlook and Dragging attachments from MS Outlook

9. Recordset: What am I doing wrong?

10. What am I doing wrong??

11. What am I doing wrong?

12. Help with syntax. What am I doing wrong

 

 
Powered by phpBB® Forum Software