none
Yet another attempt to send/recieve emails with VFP 9

    Question

  • I need to send\recieve emails with VFP 9.I have been tring the code from MegaFox to no avail. I cannot use Outlook express , I would prefer not to configure any client if possible. I am attempting to send an email from my Yahoo account to my Hotmail one. Can someome please provide me with the simplest of code to do this? It may also be nice to sent attachments and html also. Thanks

    Jim
    Wednesday, March 11, 2009 6:51 AM

Answers

All replies

  • First, you cannot send EMail without at least one EMail client configured on the host. Once an EMail client is configured, you can use CDO (the code in MegaFox is correct, and does work by the way) to send Email programmatically.

    The alternative would be go and get BLAT - that uses MAPI - see the Wiki entry for details: 
    http://fox.wikis.com/wc.dll?Wiki~BlatEmail~VFP
    -- Andy Kramek
    Wednesday, March 11, 2009 10:22 AM
  • Jim Hol said:

    I need to send\recieve emails with VFP 9.I have been tring the code from MegaFox to no avail. I cannot use Outlook express , I would prefer not to configure any client if possible. I am attempting to send an email from my Yahoo account to my Hotmail one. Can someome please provide me with the simplest of code to do this? It may also be nice to sent attachments and html also. Thanks

    Jim



    I can assure you that the code was well tested - as a matter of fact, I have been using the CDO class (with minor modification) in several production applications since 2004.

    You say that you have been trying the code from MegaFox to no avail. Could you please be a little more specific about the nature of your problem? Since you do not want to be e-mail client dependent, I assume that you are using the CDO e-mail class. What are you having trouble with? Are you getting error messages? If you can explain your problem, perhaps we can help you solve it.
    Marcia G. Akins
    Wednesday, March 11, 2009 10:45 AM
  • As per AndyKr's post above I was able to configure Outlook to finally configure to send and recieve from my Hotmail account, apprently Yahoo doesnt allow POP access from free account and Hotmail doesnt allow Outlook Express, but does allow Outlook 2003. Does this mean that if I get this to work that everyone that uses this software will need Outlook 2003?

    I am still getting this error though:

    "Program Error ole IDispatch exception Code 0 from CDO.message.1 The transport failed to connect to the server."

    So I am assuming that there is a problem in the cdoconfig table, I am not sure what it is though. Is there a way to retrieve this data automatically without entering it manually?

    Thanks for the help
    Wednesday, March 11, 2009 3:14 PM
  • I do not believe so, I believe they will need an Outlook Mail Profile created (see Control Panel - Mail).  The Outlook Profile will contain the e-mail accounts and connection settings that will allow you to send and receive e-mails.
    Wednesday, March 11, 2009 3:22 PM
  • Can this data be retrieved automatically or does it need to be entered manually? Now I am getting a different error that says "The server rejected the sender address. The server response was 530 5.7.0. Must issue a STARTTLS command first." Below is my configuration file. Can anyone see any problems or suggestions?

    Thanks

    Cfld Cval Ctype
    http://schemas.microsoft.com/cdo/configuration/languagecode en–us C
    http://schemas.microsoft.com/cdo/configuration/nntpaccountname msnews.microsoft.com C
    http://schemas.microsoft.com/cdo/configuration/nntpconnectiontimeout 60 N
    http://schemas.microsoft.com/cdo/configuration/nntpserver msnews.microsoft.com C
    http://schemas.microsoft.com/cdo/configuration/nntpserverport 119 N
    http://schemas.microsoft.com/cdo/configuration/postemailaddress   C
    http://schemas.microsoft.com/cdo/configuration/postpassword   C
    http://schemas.microsoft.com/cdo/configuration/postusername   C
    http://schemas.microsoft.com/cdo/configuration/postuserreplyemailaddress   C
    http://schemas.microsoft.com/cdo/configuration/postusing 2 N
    http://schemas.microsoft.com/cdo/configuration/sendemailaddress jimhollloway49@hotmail.com C
    http://schemas.microsoft.com/cdo/configuration/sendpassword greenspider C
    http://schemas.microsoft.com/cdo/configuration/sendusername jimhollloway49@hotmail.com C
    http://schemas.microsoft.com/cdo/configuration/sendusing 2 N
    http://schemas.microsoft.com/cdo/configuration/smtpaccountname jimhollloway49@hotmail.com C
    http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout 60 N
    http://schemas.microsoft.com/cdo/configuration/smtpserver smtp.live.com C
    http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory C:\Inetpub\mailroot\Pickup C
    http://schemas.microsoft.com/cdo/configuration/smtpserverport 587 N
    http://schemas.microsoft.com/cdo/configuration/usemessageresponsetext .T. L
    urn:schemas:calendar:timezoneid 10 N
     
    Wednesday, March 11, 2009 4:27 PM
  • Yes, you need to have a default e-mail client in your operating system. In your case can be outlook express. I think the easiest way to handle it from vfp is:

    http://www.foxite.com/articles/read.aspx?id=61&document=an-easy-way-to-send-email-from-a-visual-foxpro-application

    For yahoo, you may need a software to adapt web based yahoo to pop3, like:

    http://ypopsemail.com/

    For hotmail as I know you don't need:

    http://lifehacker.com/5151551/hotmail-enables-pop3-for-us-users
    dni
    • Marked as answer by Jim Hol Wednesday, March 11, 2009 6:34 PM
    Wednesday, March 11, 2009 4:44 PM
  • Thanks to all that helped me. This post led em to "Outlook Connector" whiched help emensely.
    Wednesday, March 11, 2009 6:34 PM
  • Jim Hol said:

    As per AndyKr's post above I was able to configure Outlook to finally configure to send and recieve from my Hotmail account, apprently Yahoo doesnt allow POP access from free account and Hotmail doesnt allow Outlook Express, but does allow Outlook 2003. Does this mean that if I get this to work that everyone that uses this software will need Outlook 2003?

    I am still getting this error though:

    "Program Error ole IDispatch exception Code 0 from CDO.message.1 The transport failed to connect to the server."

    So I am assuming that there is a problem in the cdoconfig table, I am not sure what it is though. Is there a way to retrieve this data automatically without entering it manually?

    Thanks for the help



    Actually, if you are using CDO, the easiest way to configure it is to configure Outlook Express to send mail. You never have to use Outlook Express to send e-mail, but configuring it to send creates the required registry entries for CDO to use. You do not need any e-mail client installed to use CDO to send e-mail. If you have Outlook Express installed and configured, you can use this code to retrieve some of the data:

    *** Registry roots

    #DEFINE HKEY_CLASSES_ROOT              -2147483648  && BITSET(0,31)

    #DEFINE HKEY_CURRENT_USER              -2147483647  && BITSET(0,31)+1

    #DEFINE HKEY_LOCAL_MACHINE -2147483646  && BITSET(0,31)+2

    #DEFINE HKEY_USERS                                                                            -2147483645  && BITSET(0,31)+3

     

    LOCAL lnHandle, lnProfiles, lnDataSize, lcSMTPInfo, lcCurDir, lnRes, lcSubKey, llFinished, lnCnt, lnRes2

    LOCAL lcSmtpServer, loRetVal

     

    DECLARE INTEGER RegOpenKey IN Win32API ;

          INTEGER nHKey, ;

          STRING cSubKey, ;

          INTEGER @nResult

     

    DECLARE INTEGER RegQueryValueEx IN Win32API ;

          INTEGER nHKey, ;

          STRING cValue, ;

          INTEGER nReserved, ;

          INTEGER nType, ;

          STRING @cBuffer, ;

          INTEGER @nSize     

     

    lnHandle = 0

    lnDataSize = 254

    lcSMTPInfo = SPACE( 254 )

    lnCnt = 0

    lnRes = 0

    lnRes2 = -1

    llFinished = .F.

    DO WHILE lnRes = 0 AND NOT llFinished

          lnCnt = lnCnt + 1

          lcSubKey = "Software\Microsoft\Internet Account Manager\Accounts\" + PADL( lnCnt, 8, '0' )

          lnRes = RegOpenKey( HKEY_CURRENT_USER, lcSubKey, @lnHandle )

          IF lnRes = 0

                *** Find the key that gives us the info about the SMTP Server

                lnRes2 = RegQueryValueEx( lnHandle, "SMTP Server", 0, 0, @lcSMTPInfo, @lnDataSize )

                IF lnres2 = 0

                      llFinished = .T.

                ENDIF

          ENDIF

    ENDDO

    *** Get the configuration info from the registry

    IF lnRes2 < 0 OR lnRes > 0

          *** couldn't get the info from the registry

          ASSERT .F. MESSAGE "Cannot read internet account manager setting from the registry"

          loRetVal = .NULL.

    ELSE

          *** Pass back a parameter object with the required info

          loRetVal = CREATEOBJECT( 'line' )

          WITH loRetVal

                *** We have the name of the SMTP Server

                *** Get the rest of the info

                .AddProperty( 'cServer', ALLTRIM( lcSMTPInfo ) )

                RegQueryValueEx( lnHandle, "SMTP Display Name", 0, 0, @lcSMTPInfo, @lnDataSize )

                .AddProperty( 'cDisplayName', ALLTRIM( lcSmtpInfo ) )

                RegQueryValueEx( lnHandle, "SMTP Email Address", 0, 0, @lcSMTPInfo, @lnDataSize )

                .AddProperty( 'cAddress', ALLTRIM( lcSmtpInfo ) )

          ENDWITH

    ENDIF

     

    RETURN loRetVal



    This error: Program Error ole IDispatch exception Code 0 from CDO.message.1 The transport failed to connect to the server says that something in your CDOconfig tabke is wrong - either the server name, user name or password.


    Marcia G. Akins
    Wednesday, March 11, 2009 7:19 PM
  • Hi,

    On my Win7 pc this code will not work - there is no key : Software\Microsoft\Internet Account Manager\Accounts\  Maybe that is because no OutlookExpress installed?

    Do you have an other generic solution to find programmaticaly the smtp.server name?

     

    Regards,

     

    Koen

    Sunday, July 18, 2010 11:10 PM