CDO Email strange behavoir

CDO Email strange behavoir

Postby Rick Lipkin » Sun Jul 21, 2013 4:34 pm

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)

 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: CDO Email strange behavoir

Postby lucasdebeltran » Sun Jul 21, 2013 8:19 pm

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?.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: CDO Email strange behavoir

Postby cnavarro » Sun Jul 21, 2013 8:45 pm

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
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: CDO Email strange behavoir

Postby Rick Lipkin » Mon Jul 22, 2013 1:20 pm

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
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: CDO Email strange behavoir

Postby James Bott » Mon Jul 22, 2013 7:57 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: CDO Email strange behavoir

Postby James Bott » Mon Jul 22, 2013 9:06 pm

Rick,

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

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: CDO Email strange behavoir

Postby Rick Lipkin » Mon Jul 22, 2013 10:09 pm

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
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: CDO Email strange behavoir ( solved )

Postby Rick Lipkin » Tue Jul 23, 2013 1:24 pm

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
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: CDO Email strange behavoir

Postby James Bott » Tue Jul 23, 2013 2:35 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: CDO Email strange behavoir

Postby TimStone » Tue Jul 23, 2013 3:16 pm

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
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: CDO Email strange behavoir

Postby Rick Lipkin » Tue Jul 23, 2013 4:25 pm

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)
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: CDO Email strange behavoir

Postby James Bott » Tue Jul 23, 2013 5:52 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: CDO Email strange behavoir

Postby TimStone » Tue Jul 23, 2013 7:55 pm

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
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 86 guests