Announcement

Collapse
No announcement yet.

email from my program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • email from my program

    I need some help sending email from my program. I was thinking of making the
    feature compatible with either Microsoft Outlook Express or Netscape Messenger.

    What I would like to do, is to determine which is the default mail client, and
    then to popup the applicable "New Message" form with the recipient's email address
    already inserted on the form.

    I know that for Netscape, the applicable program to shell out to is SendTo32.exe.
    But I haven't been able to determine the program to shell out to for Outlook Express.
    And I don't know how to include the recipient's email address. I was thinking of
    somehow using the clipboard, but that would at least require the user to paste the
    clipboard contents to the form.

    I also thought about using the SMTL mail program in the PowerBasic samples. But my
    ISP (Earthlink.net) won't let me.

    Is what I'm asking for possible? And if so, how would I go about it? I would very
    much appreciate some help.


    ------------------

  • #2

    Charles,

    This is very simple to do, try this code...

    Code:
    ShellExecute 0, "open", "mailto:[email protected]?Subject=Hello", "", "", %SW_SHOW
    Sometimes people underestimate the ShellExecute statement!

    Regards,

    ------------------
    Kev G Peel
    KGP Software, Bridgwater, UK.
    http://www.kgpsoftware.com
    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

    Comment


    • #3
      The SMTP sample should work. Otherwise, ShellExecute may be of help. I'm
      using the following, with Netscape as mail client, with great success.

      It's part of a customer database I have, where it picks up eventual reply
      text from a multi-line text control (hEdit) and launches the mail client
      with a new mail, with all I need already filled in, ready to press "Send".
      Don't know if it works with MSIE though..
      Code:
      '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
      ' Send as mail
      '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
      FUNCTION SendAsMail(BYVAL hEdit AS LONG) AS LONG
         IF hEdit = 0 THEN EXIT FUNCTION
         LOCAL mLen AS LONG, mStr AS STRING, mText AS STRING
       
         mLen = SendMessage(hEdit, %WM_GETTEXTLENGTH, 0, 0) + 1 'Get length of text
         IF mLen > 1 THEN
            mStr = SPACE$(mLen)
            CALL SendMessage(hEdit, %WM_GETTEXT, mLen, BYVAL STRPTR(mStr))
       
            REPLACE CHR$(13,10) WITH "%0d%0a" IN mStr    'Proper linefeed for mail
            REPLACE CHR$(32) WITH "%20" IN mStr          'Spaces
            REPLACE CHR$(38) WITH "%26" IN mStr          '&
         END IF
       
         mText = "mailto:[email protected]?"  'I pick up the mail address from a database field, but this is a sample..
         mText = mText & "Subject=" & "Reply to your question.." 'whatever..
         mText = mText & "&Body="   & mStr
         FUNCTION = ShellExecute(hEdit, "open", BYVAL STRPTR(mText), "", "", %SW_SHOWNORMAL)
       
      END FUNCTION
      ------------------

      Comment


      • #4
        Thank you both for such elegant solutions. I never expected such a brief
        solution. But I don't know why it works. I thought maybe it was shelling
        out to a file named 'MailTo.exe', but I couln't find any file of that name,
        or of anything named MailTo.

        Can one of you please fill in the missing pieces?

        ------------------

        Comment


        • #5
          What if you need to attach a file. How is that handled? Can the code be
          made to automatically include the file?

          ------------------

          Comment


          • #6
            According to RFC 2368 :
            The creator of a mailto URL cannot expect the resolver of a URL to
            understand more than the "subject" and "body" headers. Clients that
            resolve mailto URLs into mail messages should be able to correctly
            create RFC 822-compliant mail messages using the "subject" and "body"
            headers.
            Maybe it's possible to use MAPI to send a file.
            check MAPI.ZIP at http://www.powerbasic.com/files/pub/pbwin/inet/

            -p


            ------------------

            Comment


            • #7
              Charles,

              The 'mailto:' command seems to be an integral part of windows, I only found out about it after a bit of trial and error, I couldn't find it documented anywhere, but it works on all platforms.

              I don't know about file attachements, though!

              Regards,

              ------------------
              Kev G Peel
              KGP Software, Bridgwater, UK.
              http://www.kgpsoftware.com
              kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

              Comment


              • #8
                shelling is fine, until you need attachments. Though there is a command line to pass to *some* email programs, others don't support it.

                On my web site: www.basicguru.com/dickinson
                you will find a mapi wrapper (on the code page) that lets you use MAPI to send a message with attachment.

                You will also find a complete smtp email engine that is free for owners of PBDLL. It's on the shareware page and is called ddSMTP. There is a link to the free sourcecode on that page.

                The advantage of mapi is that your email will end up in the "sent items" folder of their default mail system. The disadvantage is that it requires that MAPI be properly setup and the correct email program set as the default. This sounds trivial, but it is not. You'd be suprised at the number of people that have 3 different M$ email clients installed and have to try to figure out how to make a specific one the MAPI default. The general rule of thumb is that if you can go to "FILE|SEND" from WordPad, and have it send mail correctly, the mapi wrapper will as well.

                Best Regards,
                Don

                ------------------
                www.basicguru.com/dickinson
                Don Dickinson
                www.greatwebdivide.com

                Comment


                • #9
                  Thank you all for your responses

                  Don, I was unsuccessfull using your ddsmtp program, probably for the same
                  reason that I can't use the PowerBasic smtp sample program. Earthlink gives
                  back an error msg:
                  'HELO error: 220-NO UCE. Earthlink network does not authorize the use of
                  its computers'

                  The ShellExecute works pretty well, except when not online, Netscape loads
                  two copies of the composition dialog box, as well as the Netcape window.
                  But after making Outlook Express the default mail client, ShellExecute brings
                  up just the single Microsoft mail dialog box which is what I want. I wish I
                  could get the Microsoft mail dialog box to pop up without having to go into
                  Outlook Express first just to make it the default mail client. Wordpad does
                  this somehow, but I haven't been able to figure out how. Does anyone know
                  how to bring up just a single mail dialog box?

                  I am using the following short program to experiment with ShellExecute.

                  Code:
                  #COMPILE EXE
                  #DIM ALL
                  #INCLUDE "win32api.INC"
                  DECLARE CALLBACK FUNCTION dlgProc()
                  FUNCTION PBMAIN
                     LOCAL hDlg AS LONG
                     DIALOG NEW 0, "Email Test", , , 200, 85, %WS_SYSMENU + %WS_CAPTION TO hDlg
                     CONTROL ADD BUTTON, hDlg, %IDOK, "&Email", 5, 20, 90, 14
                     CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Cancel", 5, 40, 90, 14
                     DIALOG SHOW MODAL hDlg CALL dlgProc
                  END FUNCTION
                  
                  CALLBACK FUNCTION dlgProc()
                     LOCAL emailStr AS STRING
                     SELECT CASE CBMSG
                     CASE %WM_COMMAND
                        SELECT CASE CBCTL
                           CASE %IDOK
                              emailStr = "[email protected]?"
                              ShellExecute CBHNDL, "open", "mailto:" + emailStr, "", "", %SW_SHOW
                           CASE %IDCANCEL
                              DIALOG END CBHNDL
                           END SELECT
                     CASE %WM_DESTROY
                     END SELECT
                  END FUNCTION
                  ------------------

                  Comment

                  Working...
                  X