NetTalk Central

Author Topic: "working" code doesn't send email  (Read 5239 times)

KraigW

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
"working" code doesn't send email
« on: July 24, 2013, 01:10:27 PM »
I'm experimenting with NetTalk to create and send emails.  From the example code I have built a short test routine and I have successfully called the routine and sent email from an embed of a button on a window.

But copying the same code into a Process procedure in the last INIT embed does not work.  But No compile errors.

It sure looks like the extensions are set up the same way in both procedures.  My code is below.  Am I missing something?


         
         ThisEmailSend.Server              = 'smtpout.secureserver.net'   
         ThisEmailSend.Port                = 80 ! 25
         ThisEmailSend.ToList              = 'kraigwhiting@gmail.com'
         ThisEmailSend.ccList              = ''
         ThisEmailSend.bccList             = ''
         ThisEmailSend.From                = 'kraig@commandelectronics.com'
         ThisEmailSend.Subject             = 'test email' !MySubject
         ThisEmailSend.Helo                =  'commandelectronics.com'
         ThisEmailSend.AttachmentList      = ''
         ThisEmailSend.SSL                 = 0 
         ThisEmailSend.SecureEmailStartTLS = 0
     
         if ThisEmailSend.SSL or ThisEmailSend.SecureEmailStartTLS
            ThisEmailSend.SSLCertificateOptions.CertificateFile = ''
            ThisEmailSend.SSLCertificateOptions.PrivateKeyFile = ''
            ThisEmailSend.SSLCertificateOptions.DontVerifyRemoteCertificateWithCARoot = 0
            ThisEmailSend.SSLCertificateOptions.DontVerifyRemoteCertificateCommonName = 0
            ThisEmailSend.SSLCertificateOptions.CARootFile = '.\caroot.pem'
         end
       
         if ThisEmailSend.SecureEmailStartTLS
            ThisEmailSend.SSLCertificateOptions.DontVerifyRemoteCertificateCommonName = 1
            ! Fudge this for now, as the certificate is not known
            ! when NetSimple does the CommonName check
         end
     
         ThisEmailSend.SetRequiredMessageSize (0,len(clip('this looks very promising')),len(clip('This looks <b>very</b> promising.')))
            !You must call this function
            !before populating self.MesageText
     
         Thisemailsend.AuthUser     = 'kraig@commandelectronics.com'
         thisemailsend.AuthPassword = 'NotMyRealPassword'
     
         if ThisEmailSend.Error = 0 ! Check for error         
                   
             
            if len(clip('this looks very promising')) > 0
               ThisEmailSend.MessageText = clip ('this looks very promising')
            end
     
            if len(clip('This looks <b>very</b> promising.')) > 0
               ThisEmailSend.MessageHTML = clip ('This looks <b>very</b> promising.')
            end
             
            setcursor (CURSOR:WAIT)
            display()
            ThisEmailSend.SendMail(NET:EMailMadeFromPartsMode)
            ! Put email in queue and start sending it
            setcursor
            display()     
          ELSE
            message('ThisEmailSend.Error > 0',Thisemailsend.Error)
         end

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: "working" code doesn't send email
« Reply #1 on: July 24, 2013, 03:25:03 PM »
I think it needs a normal window. what I do is just setup a normal window to email and then call that procedure from where-ever I want and pass it the info it needs to send the email. so in your case call that procedure from your process.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: "working" code doesn't send email
« Reply #2 on: July 24, 2013, 09:24:00 PM »
the problem is probably not in the code, but in the fact that the process procedure "ends" before the mail has actually been sent.
Remember the mail is asynchronous (like all NetTalk communications) so when you "start sending" it means exactly that - it's just starting.

Rather than a Process procedure I'd recommend a normal window - which then handles ErrorTrap and Done methods correctly. See "Sending email from a Process" example for a good example of it.

cheers
Bruce