Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to send email with an attachment, Visual C++ 6.x

144 views
Skip to first unread message

Harold DeWayne

unread,
Feb 19, 2006, 1:29:13 PM2/19/06
to
I know how to create a new email message addressed to myself in my
program using the following code

ShellExecute (GetSafeHwnd(), "open", "mailto:harold-...@juno.com",
NULL, NULL, SW_SHOWNORMAL);

but can someone tell me how to attach the current file from the open
document? I'm currently using a CTreeView document, but all I want to
forward is the open document on disk (not the tree). I know how to
retrieve the document filename but attaching a copy of that document
to the email is beyond my current abilities.

Thanks in advance

Harold DeWayne

Kellie Fitton

unread,
Feb 19, 2006, 3:01:33 PM2/19/06
to

Mars

unread,
Feb 26, 2006, 9:16:59 PM2/26/06
to
Hope the following code helps, I use it working:
void SendEMail(
char *pszRecvAddress, //Email
char *pszTitle, //Mail Title
char *pszNotes, //Mail Content
char *pszFileName //attachment file name
)
{
if ((NULL == pszRecvAddress) ||
(NULL == pszTitle) ||
(NULL == pszNotes) ||
(NULL == pszFileName)
)
{
printf("ERROR:NULL on SendEMail Function parameter!!!\n");
return;
}

ULONG uRetCode = 0;
LPMAPISENDMAIL lpMAPISendMail = NULL;
HMODULE hLibMAPI = NULL;
MapiRecipDesc ReceiverInfo = {0, MAPI_TO, "", pszRecvAddress,
0, 0};
MapiFileDesc AttachmentInfo = {0, 0, 0xFFFFFFFF, pszFileName,
"", NULL};
MapiMessage MailInfo =
{
0,
pszTitle,
pszNotes,
NULL,
NULL,
NULL,
MAPI_SENT,
NULL,
1,
&ReceiverInfo,
1,
&AttachmentInfo
};


hLibMAPI = ::LoadLibrary("MAPI32.DLL");
if (NULL == hLibMAPI)
{
printf("ERROR on Load MAPI32.DLL file!!! Cancel to auto send
mail!!!\n");
return;
}
lpMAPISendMail = (LPMAPISENDMAIL)::GetProcAddress(hLibMAPI,
"MAPISendMail");
if (NULL == lpMAPISendMail)
{
printf("ERROR on Get MAPISendMail Function Address!!! Cancel to
auto send mail!!!\n");
goto ERR_EXIT;
}

uRetCode = lpMAPISendMail(0L, 0L, &MailInfo, 0, 0);
if (SUCCESS_SUCCESS == uRetCode)
{
printf(
"Success to Send mail to: %s, Mail Title:%s, Mail
Notes:%s,Attachment file name:%s\n",
pszRecvAddress,
pszTitle,
pszNotes,
pszFileName
);
}
else
{
printf("ERROR:failed Send mail!\n");
}

ERR_EXIT:
if (NULL != hLibMAPI)
{
::FreeLibrary(hLibMAPI);
hLibMAPI = NULL;
}

return;
}

0 new messages