CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2001
    Posts
    148

    URGENT ..Mailing using ShellExecute

    hai all

    i want to use ShellExecute to invoke the default mail program
    and add subject ,body and an attachment
    then what should be the command line
    i tried with this

    mailto:[email protected]?subject=test subject&body=test body&attachment="c:\attach.txt"

    but the attachment does not work

    thnks
    akg



  2. #2
    Join Date
    Feb 2001
    Posts
    148

    Re: URGENT ..Mailing using ShellExecute

    no one there


  3. #3
    Join Date
    May 2001
    Location
    Beijing, China
    Posts
    234

    Re: URGENT ..Mailing using ShellExecute

    Try:

    ShellExecute(NULL,"open","MailTo:[email protected]?subject=your subject&body=your body&attachment=\"c:\\attach.txt\"",NULL,NULL,SW_SHOWNORMAL);





    [i]Rate it if it helps

  4. #4
    Join Date
    Feb 2001
    Posts
    148

    Re: URGENT ..Mailing using ShellExecute

    thanks for the replay


    this did't work.. the attachment was not there
    i want that thing




  5. #5
    Join Date
    May 2001
    Location
    Beijing, China
    Posts
    234

    Re: URGENT ..Mailing using ShellExecute

    Does this attachment file exist in your disk?
    It works fine in my machine, I use VC 6.0 and outlook.



    [i]Rate it if it helps

  6. #6
    Join Date
    Feb 2001
    Posts
    148

    Re: URGENT ..Mailing using ShellExecute

    Thanks 4 the replay


    yes the file was present...
    i'am working in 2k/vc6.0 ,but the code didn't work..

    thanks akg



  7. #7
    Join Date
    Nov 2001
    Posts
    1

    Re: URGENT ..Mailing using ShellExecute

    i have tested it!
    i have no attachment too!
    vc6.0+outlook express


  8. #8
    Join Date
    Feb 2001
    Posts
    148

    Re: URGENT ..Mailing using ShellExecute

    Why does it some times work and other times it does not ??


  9. #9
    Join Date
    Mar 2001
    Location
    Albuquerque, NM
    Posts
    12

    Re: URGENT ..Mailing using ShellExecute

    Outlook Express does not allow you to add an attachment via ShellExecute().

    Try using MAPI. It is simple and works very well.
    Here is an example that fires off an email with attachment. Note that as written, it requires NO input from user.

    #include <mapi.h>
    void CMyApp::OnMySendMail()
    {
    HMODULE hLib=::LoadLibrary("MAPI32.DLL");
    if (hLib == NULL)
    {
    AfxMessageBox(AFX_IDP_FAILED_MAPI_LOAD);
    return;
    }

    ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
    (FARPROC&)lpfnSendMail = GetProcAddress(hLib, "MAPISendMail");
    if (lpfnSendMail == NULL)
    {
    AfxMessageBox(AFX_IDP_INVALID_MAPI_DLL);
    return;
    }

    // prepare the file description (for the attachment)
    MapiFileDesc fileDesc;
    memset(&fileDesc, 0, sizeof(fileDesc));
    fileDesc.nPosition = (ULONG)-1;
    fileDesc.lpszPathName = "c:\\netlog.txt";

    // prepare the recipient description.
    MapiRecipDesc recip;
    memset(&recip, 0, sizeof(recip));
    recip.ulRecipClass = MAPI_TO;
    recip.lpszAddress = "[email protected]";

    // prepare the message (empty with 1 attachment)
    MapiMessage message;
    memset(&message, 0, sizeof(message));
    message.lpszSubject = "This is a TEST!!!";
    message.lpszNoteText = " Dave Paxton\n 1-234-567-8901\n [email protected]";

    // Recipients.
    message.nRecipCount = 1;
    message.lpRecips = &recip;

    // Attachments.
    message.nFileCount = 1;
    message.lpFiles = &fileDesc;

    int nError = lpfnSendMail(0, 0, &message, 0, 0);
    ::FreeLibrary(hLib);

    ASSERT(nError == SUCCESS_SUCCESS);
    }



    Forgive the formatting, even with the formating markup, it got ruined.
    Geno



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured