Send e-mail attachments?

  • Thread starter Thread starter Torben Jensen
  • Start date Start date
T

Torben Jensen

Hello!

I want to be able to send fileattachements from my application using the
default mail client.

Reading various articles it has come to my attention that this can be
accomplished by using the mapi32.dll and teh MAPISendDocuments() functions.
This seems rather complex to me and I have not been able to find any
examples showing how to use this dll.
If someone should have eny helping links or any other helpful guidelines it
would be just great.

Thank you.
Torben

PS. the reason why I am not using the SmtpMail class is that it is important
to me to use the default mail client and still be able to send attachments.
 
Try

[DllImport("MAPI32.DLL", CharSet=CharSet.Ansi)]
public static extern uint MAPISendDocuments(IntPtr ulUIParam, string
lpszDelimChar, string lpszFullPaths, string lpszFileNames, uint ulReserved);

and then call

string fullFileName = "c:\sample.txt";
MAPISendDocuments(this.Handle, System.IO.Path.PathSeparator.ToString(),
fullFileName, System.IO.Path.GetFileName(fullFileName), 0);

Regards,
Phil.
 
Hi Phil!

Your approach seems quite easy to get a hold on, I am thoug experiencing
some problems.

I am using c# is this a problem? I don't know where to put the DllImport
statement, can one use that in c# or is it only meant for c++?
[DllImport("MAPI32.DLL", CharSet=CharSet.Ansi)]
public static extern uint MAPISendDocuments(IntPtr ulUIParam, string
lpszDelimChar, string lpszFullPaths, string lpszFileNames, uint
ulReserved);

The parameters used above, do I have to set them manually or how does it
work?

Hope you can help me on this one.

Thank you.
Torben
 
I'm using C# too. I keep all my mapi stuff in a code file MapiLib.cs

using System;
using System.Runtime.InteropServices;

class MapiLib
{
static MapiLib()
{
}

[DllImport("MAPI32.DLL", CharSet=CharSet.Ansi)]
public static extern uint MAPISendDocuments(IntPtr ulUIParam, string
lpszDelimChar, string lpszFullPaths, string lpszFileNames, uint ulReserved);
}

I've removed all the other mapi functions (MAPILogon, MAPILogoff etc) for
clarity. Then you just need to call MapiLib.MAPISendDocuments...

Regards,
Phil.

Torben Philippsen said:
Hi Phil!

Your approach seems quite easy to get a hold on, I am thoug experiencing
some problems.

I am using c# is this a problem? I don't know where to put the DllImport
statement, can one use that in c# or is it only meant for c++?
[DllImport("MAPI32.DLL", CharSet=CharSet.Ansi)]
public static extern uint MAPISendDocuments(IntPtr ulUIParam, string
lpszDelimChar, string lpszFullPaths, string lpszFileNames, uint
ulReserved);

The parameters used above, do I have to set them manually or how does it
work?

Hope you can help me on this one.

Thank you.
Torben
 
Hi Phil,

Thank you very much, I finally got it to work. The only thing I was missing
was to add the
using System.Runtime.InteropServices;

Best regards Torben
 
Back
Top