Page 1 of 1

CDO Email strange behavoir

PostPosted: Sun Jul 21, 2013 4:34 pm
by Rick Lipkin
To All

I have been trying to use CDO to send SMTP e-mail from a Project Management application I am writing. I have created a Gmail account and I use Rafa's CDO code mentioned in the Spanish forum... and I have been successful. Unfortunately, when I login to a different network or location ( other than the location\Network that created the Gmail account ) the CDO e-mail fails every time.

I am just curious ... I have the same code that runs flawlessly from my office ( location and IP where I created the gmail account ) .. has anyone experienced this behavor in any applications they are currently using ?

To clarify .. I am using gmail as an SMTP relay to distribute my application's e-mail to various Project stakeholders.

Again .. this code runs perfectly from my office ... but if I login to a different network and run the same code .. it fails.

Any Ideas??

Rick Lipkin

Code: Select all  Expand view

//---------------------------------------------
Function _SendMail(cSmtp_Host,nPort,lSsl,;
                           cSmtp_UserId,cSmtp_Password,cFrom,cTo,aCC,cSubject,cMessage,oDlg)

Local oEmailCfg,oErr,lFailed,oEmailMsg,cAddress,i

SysReFresh()

// smtpauthenticate
// 0 cdoAnonymous Perform no authentication.
// 1 cdoBasic     Use the basic (clear text) authentication mechanism.
// 2 cdoNTLM      Use the NTLM authentication mechanism.

If empty(aCC)
   cAddress := ""
Else
   For i = 1 to Len(aCC)
       If i = 1
          cAddress := aCC[i]
       Else
          cAddress := cAddress+","+aCC[i]
       Endif
    Next
Endif

lFailed := .f.
TRY
  oEmailCfg := CREATEOBJECT( "CDO.Configuration" )
  WITH OBJECT oEmailCfg:Fields                                                          // cSmtp_Host
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value       := cSmtp_Host  //::smtpServer
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value   := nPort //465 //::smtpPort
  :Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value        := 2 //::sendusing  // Remote SMTP = 2, local = 1
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := 1 //::AUTH // 0 , 1 ,2
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value       := lSsl //::SSL
  :Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value     := cSmtp_Userid   //::username
  :Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value     := cSmtp_Password
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 15 //::TimerOut
  :Update()
  END WITH

CATCH oError
   MsgInfo( "Error in Configuration" )
END

oError := NIL
TRY
   oEmailMsg  := CREATEOBJECT ( "CDO.Message" )
   WITH OBJECT oEmailMsg
        :Configuration = oEmailCfg
        :From     := cFrom
        :To       := cTo
        :CC       := cAddress

        :BCC      := ""
        :Subject  := cSubject
     // :MDNRequested = .T.       // Solicitud de reconocimiento, o acuse de recibo
        :TextBody := cMessage

        * for each cFile in ::aFiles
                *    :AddAttachment( cfile )
        * next
        :Fields:update()
        :Send()
     // ? "[ "+Time()+" ] Enviado correo :"+ ::email
   END
CATCH oError
      MsgINfo("Error in sending e-mail:"+  oError:Description )
      lFailed := .t.
END

oEmailCfg := NIL
oEmailMsg := NIL

oDlg:End()
SysRefresh()

Return(lFailed)

 

Re: CDO Email strange behavoir

PostPosted: Sun Jul 21, 2013 8:19 pm
by lucasdebeltran
Rick,

Sometimes, if gmail detect that the account is being used from another location it asks to enter a veryfication code.

Maybe this will be the issue.

Can you use another SMTP provider, ie Amazon cloud services?.

Re: CDO Email strange behavoir

PostPosted: Sun Jul 21, 2013 8:45 pm
by cnavarro
For it could be useful
Verify that you have activated the option "two-step verification" of your account. (Security)

If so, in Gmail maybe have to enlist the application that you are using and does not allow that protocol and assign a password. When you walk from this application have to put the password defined for that application, not the account.
Not if he has anything to do with your problem.
This text is translated Translate, so I recommend you look in Google "two-step verification GMail".
I've also had a problem on computers that the user has activated the option "Do not close session".
I hope you can fix it.
regards

http://www.genbeta.com/correo/que-es-la-verificacion-en-dos-pasos-de-gmail-y-por-que-es-importante-activarla

Por si te puede ayudar
Comprueba que no tienes activada la opcion "Verificacion en dos pasos" de tu cuenta. (Seguridad)

Si es asi, en Gmail quizas tengas que dar de alta la aplicacion que vas a usar y que no permite ese protocolo y ponerle una contraseña. Cuando entras desde esa aplicacion tienes que poner la contraseña definida para esa aplicacion y no la de la cuenta.
No se si tiene algo que ver con tu problema.
Este texto esta traducido con Translate, por lo que te recomiendo que busques en Google "Verificacion en dos pasos de GMail".
Tambien he tenido algun problema en equipos en los que el usuario tiene activa la opcion "No cerrar sesion".
Espero que puedas solucionarlo.
Saludos

Re: CDO Email strange behavoir

PostPosted: Mon Jul 22, 2013 1:20 pm
by Rick Lipkin
Cristobal

I have done some research on Google searching for 'gmail smtp relay' .. and it does seem to be possible.

I have entered and verified my security code and the account is active. I am using port 465 and some of the research suggests using port 587.

I am continuing my research.

Thanks
Rick Lipkin

Re: CDO Email strange behavoir

PostPosted: Mon Jul 22, 2013 7:57 pm
by James Bott
Rick,

Two things to try. Check to make sure that the port isn't being blocked at the customer's site. Also, try increasing the timeout interval (it is normally 30).

:Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 30

Is your code trapping and displaying errors? If not add it. OK, that was three things.

James

Re: CDO Email strange behavoir

PostPosted: Mon Jul 22, 2013 9:06 pm
by James Bott
Rick,

Another thought. The customer company may be intentionally blocking the Gmail site to prevent employees from accessing their personal mail at work.

James

Re: CDO Email strange behavoir

PostPosted: Mon Jul 22, 2013 10:09 pm
by Rick Lipkin
James

I had a second set of eyes look at this and I was getting the infamous "Member not found" ADO error which doesn't really tell me much ..

Here is what I found and this seems to be the fix .. the cFrom when dealing with gMail has to be a fully distinguished email address rather than just a value even if it is a dummy name and domain.

cFrom := "PMO Admin" // works on my machine but fails everywhere else
cFrom := "PMO_Admin@bogus.com" // works all the time :shock:

Apparently when I created my gMail account .. CDO must have pulled a value ( perhaps from the registry ) from my machine and plugged in the value of cFrom and the email was delivered as <Pmo Admin>. Using "Pmo_Admin@bogus.com" ( fully distinguished address ) allows the email to be sent and it does get delivered.

I have tested this fix on a different machine in my office and it worked great ( which previously errored to ) .. what I have not done is to test this again on my laptop logged into a different network.

I think everything should work .. I will let you know in the morning. :)

Rick Lipkin

Re: CDO Email strange behavoir ( solved )

PostPosted: Tue Jul 23, 2013 1:24 pm
by Rick Lipkin
To All

As I mentioned in the last post .. sending email with CDO is quite possible and using gMail as a 'SMTP RELAY' is a great way to integrate sending e-mail from your applications.

The final solution ( specific to gmail ) was to put a qualified e-mail address in the 'from' parameter even if it is not a real address .. as log as you have a name and domain ( name@bogus.com ) .. along with a legitimate 'to' .. CDO and gMail makes a great combination.

Rick Lipkin

Re: CDO Email strange behavoir

PostPosted: Tue Jul 23, 2013 2:35 pm
by James Bott
Rick,

Glad to hear you solved the problem.

I always specify the From field like this:

cFrom:= ["James Bott" <jbott@whatever.com>]

I never tried using a bogus email address during testing--I just send test emails to myself.

Regards,
James

Re: CDO Email strange behavoir

PostPosted: Tue Jul 23, 2013 3:16 pm
by TimStone
I implemented CDO several months back and resolved the remaining SSL issues some of my clients faced.

With that said, I do NOT use Gmail. It would not surprise me that any corporation or individual who seeks to not have 100% of their information broadcast to the world would block Gmail. Please carefully read the Privacy Policy ( very easily found ) that applies to all Google services ( and doesn't that include Android phones ? ) . Because I often handle items for others, I cannot voluntarily submit their information to a global server to be sold to anyone with any interest.

Nothing is ever FREE. Everything has a cost, and the fee for using "free" services is to allow them to do whatever they want with your data.

Tim

Re: CDO Email strange behavoir

PostPosted: Tue Jul 23, 2013 4:25 pm
by Rick Lipkin
Tim

I truly understand your concerns .. when using SMTP Relay .. I am using the gMail service to just distribute my e-mail. None of the messages are stored anywhere on any gMail account.

All I have done is created a gmail account and then use CDO to point it to SMTP.GMAIL.COM, port 465 with SSl and furnish my email credentials UserId and Password.

I can direct mail, cc, bc to anyone I want and all gMail does is handle the Relay.. nothing is stored anywhere, Google is just the traffic handler.

Rick Lipkin

ps .. and it is free 8)

Re: CDO Email strange behavoir

PostPosted: Tue Jul 23, 2013 5:52 pm
by James Bott
Rick,

Well, just because you don't store it, doesn't mean that Google doesn't.

Tim, which SMTP server are you using? Or, do you have your own mail server setup?

James

Re: CDO Email strange behavoir

PostPosted: Tue Jul 23, 2013 7:55 pm
by TimStone
Rick,

It doesn't have to be stored there. Anything you touch Google is recorded ... even your searches, and cross referenced. The EU is now on the verge of assessing massive fines for privacy violations against them.

James,

I have Microsoft hosted Exchange accounts. They have a different policy. Its only $4 a month and totally worth the cost. I can also use email accounts with my web hosting service, and that is unlimited.

Tim