• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

Sending an email attachment from default email client

I'm developing a desktop application in C++ (using MS Visual stdio 6.0) and I have from following requirement:

 - the application must launch the default email client on the user's PC to send an email (easy using ShellExecuteEx)
 - it must then attach a binary file to the message (this seems to be the hard part!).
 - it needs to work for all the popular email clients (eg. Outlook Express, Eudora, MS Outlook etc)

I've seen several threads already that show how to program using the SMTP protocol to send the message with an attachment directly to the server, but this is NOT what I want do do. I also don't want the user to have to re-enter the the server address/authentication password etc in my program - after all, they've already configured their email client for this once!.

Thanks in advance for any help with this.
0
Schmapper
Asked:
Schmapper
  • 3
1 Solution
 
jkrCommented:
You can do that quite easily using "Simple MAPI" - see e.g. http://msdn.microsoft.com/library/en-us/mapi/html/22935289-976c-46d2-9091-5941172f449d.asp ("Handling Attachments with Simple MAPI") and http://msdn.microsoft.com/library/en-us/mapi/html/18568453-273d-4bb7-abc2-de382bad5034.asp ("Sending a Message Simply: Simple MAPI Sample"):

// Example 1:
// Send a mail message containing a file and prompt for
// recipients, subject, and note text.

ULONG err;
MapiFileDesc attachment = {0,         // ulReserved, must be 0
                           0,         // no flags; this is a data file
                           (ULONG)-1, // position not specified
                           "c:\\tmp\\tmp.wk3",  // pathname
                           "budget17.wk3",      // original filename
                           NULL};               // MapiFileTagExt unused
// Create a blank message. Most members are set to NULL or 0 because
// MAPISendMail will let the user set them.
MapiMessage note = {0,            // reserved, must be 0
                    NULL,         // no subject
                    NULL,         // no note text
                    NULL,         // NULL = interpersonal message
                    NULL,         // no date; MAPISendMail ignores it
                    NULL,         // no conversation ID
                    0L,           // no flags, MAPISendMail ignores it
                    NULL,         // no originator, this is ignored too
                    0,            // zero recipients
                    NULL,         // NULL recipient array
                    1,            // one attachment
                    &attachment}; // the attachment structure
 
err = MAPISendMail (0L,          // use implicit session.
                    0L,          // ulUIParam; 0 is always valid
                    &note,       // the message being sent
                    MAPI_DIALOG, // allow the user to edit the message
                    0L);         // reserved; must be 0
if (err != SUCCESS_SUCCESS )
    printf("Unable to send the message\n");

(You'll have to 'MAPIInitialize()' before)
 
0
 
jkrCommented:
OH, BTW, you might find http://www.codeproject.com/internet/xymailclient.asp ("Sending and receiving e-mails from your program") or http://www.codeproject.com/internet/cimapi.asp ("Another simple MAPI class") to come in handy.
0
 
SchmapperAuthor Commented:
Thanks jkr.

The MAPI solution certainly seems to work with my current email client (Eudora). Still need to check it out with MS Outlook and Outlook Express also and if these are successful, then I'll accept your solution. One thing I found was that I didn't need to call MAPIInitialise but did need to dynamically load in the MAPI32 dll to access the MAPISendMail function. Do you happen to know about the availability of the MAPI32 dll? Would it have been shipped with all Window O/S versions going back to, say, Windows 95, for example? Just need to determine whether I would need to bundle it with my application or not?
0
 
jkrCommented:
Both OL and OE will work with MAPI, I am not really worried about that.

>>Do you happen to know about the availability of the MAPI32 dll?

Check http://support.microsoft.com/dllhelp/ for detailed info on that, but MAPI certainly is available on all platforms that are able to run Outlook Express :o)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now