A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.
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.
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.
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.
Tuesday, July 25, 2006
You're looking for MAPI. Do a Google Groups search for "Delphi MAPI" and you should get several Delphi component links.
Tuesday, July 25, 2006
To be precise, you want "Simple MAPI" whereas MAPI is now generally used to refer to the Outlook API.
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.
Here is some sample code:
HWND hwndParent = NULL;
const char* pszAttachPathname = "c:\\temp\\test.txt";
const char* pszAttachFilename = "test.txt";
const char* pszTo = "email@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 )
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
"how do you do that to large-ish distribution lists"
I think you need to look into the SMTP route.
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.
You can find a free Delphi mapi mail unit at:
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.
Friday, July 28, 2006
This topic is archived. No further replies will be accepted.Other recent topics
Powered by FogBugz