Click here to Skip to main content
15,914,795 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi,
I'm creating a mail and I'm trying to attach a file to the mail. My problem is when I click the attach button the browse window appears, the option is able to attach but the attachment is not recieved in the reciever(outlook) only the mail is recieved. I don't know what coding I forgot. Please say me what coding I forgot.
void CZapMailDlg::OnAttachfiles() 
{
	// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
	CString file;
   // **** I had some proble with the flags OFN_ALLOWMULTISELECT of the CFileDialog ?????
   // **** If I took multiple selection bigger then I could view on the selection, the list
   // **** returned is bad ???
   CFileDialog dialog(TRUE,_szFilter,NULL, OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER);
   dialog.DoModal();
   POSITION pos = dialog.GetStartPosition();
   while (pos != NULL)
   {
      file = dialog.GetNextPathName( pos );
      m_ListBox.AddString(file);
   }

thank you
Posted
Updated 25-Apr-11 18:48pm
v2

1 solution

In your code, you are only adding the file names to a list box. Since you don't show where you are sending the email, we can't really tell what is missing.

I found 2 links that might help on sending attachments using MFC:

http://support.microsoft.com/kb/200174[^]
http://www.example-code.com/mfc/smtp_sendEmailWithAttach.asp[^]

Also, when you are using OFN_ALLOWMULTISELECT, you must ensure that the buffer is large enough to contain all the file names:
C++
CFileDialog dialog(TRUE,_szFilter,NULL, OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST);
//before displaying the dialog
//give a big buffer to store the file names
TCHAR buffer[5000];
dialog.m_ofn.lpstrFile = buffer;
dialog.m_ofn.nMaxFile = sizeof(buffer) / sizeof(TCHAR);
if (dialog.DoModal() == IDOK)
{
   //user clicked OK
   ...
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900