The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Creating email with attachment to default mail client?

Does anyone know of a clean way to create an email with an attached file using the system's registered mail client?  I'd like to be able to have a "Send To" function for documents housed in an internal datastore.  Applications like WinRar do a good job at this and I was wondering if anyone has done something similar or has a suggestion on a good approach.  I'd like to avoid using the Outlook API's directly if possible for this task.
melon_helmet
Monday, July 24, 2006
 
 
I'd like a solution to this, too.  And while we're talking about it, how do you do that to large-ish distribution lists (with or without attachments).  I'd like to be able to click a button in my application and send e-mail to dozens of recipients but all the methods I've tried maxed out with a pretty limited number of recipients.
Chris Nelson Send private email
Tuesday, July 25, 2006
 
 
What language?
J.B. Send private email
Tuesday, July 25, 2006
 
 
I want a Tcl implementation but give it to me in C or tell me what DLLs to access and I'll make it work.
Chris Nelson Send private email
Tuesday, July 25, 2006
 
 
I'm contemplating Delphi or .NET, so anything COM based should do.  However, I wanted to avoid using application specific API's if at all possible.
melon_helmet
Tuesday, July 25, 2006
 
 
melon_helmet,

You're looking for MAPI. Do a Google Groups search for "Delphi MAPI" and you should get several Delphi component links.

Ken
Ken
Tuesday, July 25, 2006
 
 
To be precise, you want "Simple MAPI" whereas MAPI is now generally used to refer to the Outlook API.
Ben Bryant
Tuesday, July 25, 2006
 
 
SMAPI is pretty brain-dead and, last I heard, obsolete and unsupported.  I've tried to use it before.  I cursed the developer.

I've heard it suggested that accessing your Exchange server via SMTP isn't a bad route.  I haven't explored that fully yet.
Chris Nelson Send private email
Tuesday, July 25, 2006
 
 
Assuming you're talking Windows, Simple MAPI works fine. Funny that someone would call Simple MAPI obsolete when thousands of programs continue to depend on it. It is because it is old that it is more dependable. It is only obsolete in the sense that it can't do anything complicated, but for what you're after it is the best solution because it works with clients other than Outlook, and you can do it in about 15 or 20 lines of C code.
Ben Bryant
Tuesday, July 25, 2006
 
 
Here is some sample code:

#include <MAPI.h>
HWND hwndParent = NULL;
const char* pszAttachPathname = "c:\\temp\\test.txt";
const char* pszAttachFilename = "test.txt";
const char* pszTo = "someone@example.com";
const char* pszBody = "blah blah";
ULONG (PASCAL *lpfnMAPISendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
HMODULE hMAPI = LoadLibrary( "MAPI32.DLL" );
int nError = -1;
if ( hMAPI )
{
(FARPROC&)lpfnMAPISendMail = GetProcAddress(hMAPI,"MAPISendMail");
if ( lpfnMAPISendMail )
{
MapiMessage message;
MapiFileDesc filedesc;
MapiRecipDesc recip;
memset( &message, 0, sizeof(message) );
if ( pszAttachPathname )
{
ZeroMemory( &filedesc, sizeof(MapiFileDesc) );
filedesc.nPosition = (ULONG)-1;
filedesc.lpszPathName = pszAttachPathname;
filedesc.lpszFileName = pszAttachFilename;
message.nFileCount = 1;
message.lpFiles = &filedesc;
}
ZeroMemory( &recip, sizeof(MapiRecipDesc) );
recip.ulRecipClass = MAPI_TO;
recip.lpszName = pszTo;
message.nRecipCount = 1;
message.lpRecips = &recip;
message.lpszSubject = (char*)(LPCTSTR)csSubject;
message.lpszNoteText = pszBody;
// Bring up the send message dialog
nError = lpfnMAPISendMail(0, (ULONG)hwndParent, &message, MAPI_LOGON_UI|MAPI_DIALOG, 0);
}
FreeLibrary( hMAPI );
}
return nError; // 0/SUCCESS_SUCCESS 1/MAPI_USER_ABORT, 11/MAPI_E_ATTACHMENT_NOT_FOUND
Ben Bryant
Tuesday, July 25, 2006
 
 
Ben, thanks again.  This is exactly what I was looking for.
melon_helmet
Tuesday, July 25, 2006
 
 
"how do you do that to large-ish distribution lists"
I think you need to look into the SMTP route.
Ben Bryant
Tuesday, July 25, 2006
 
 
SMAPI is brain-dead in that there are NO introspection capabilities.  As I recall -- it's been a couple of years since I tried it -- you can't even relably tell if it's installed and enabled on the system.  When it works, it work.  And old and reliable is great but it's a very poorly designed API.
Chris Nelson Send private email
Wednesday, July 26, 2006
 
 
Doesn't the use of MAPI limit your choice of clients ?
nobody
Thursday, July 27, 2006
 
 
You can find a free Delphi mapi mail unit at:

http://www.scalabium.com/mapimail.htm
Herbert Sitz Send private email
Thursday, July 27, 2006
 
 
The basic SendMail function of Simple MAPI is supported by almost every e-mail client. The more arcane functions and the full MAPI API is properly supported only by Microsoft clients.
Chris Nahr Send private email
Friday, July 28, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz