FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour SEND EMAIL
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: SEND EMAIL
Posted: Sun Mar 24, 2013 06:58 PM
Tim,

I would sure love an SMTP system that works . Sadly, the native system to FWH does not support SSL either, nor does it support attachments.


FWH's TSMTP class does support attachments. There are two issues to keep in mind. First, the attachment name has to include the full path and drive letter. Second, if you are using a temp file as an attachment, you have to put in a delay before deleting the temp file or it may get deleted before it is mailed. If you are still having problems with attachments, then please post your code here and maybe I can find the problem.

Regards,
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: SEND EMAIL
Posted: Mon Mar 25, 2013 05:11 PM

I've had attachments all along but I'm using an updated version of tSMTP. The last time I looked, that was still not part of the one included in the libraries.

However, none of those support SSL.

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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: SEND EMAIL
Posted: Wed Apr 03, 2013 05:19 PM
Enrico Maria Giordano wrote:I'm getting erratic errors from Send() method that is not replicable. Anyone got that error and found a way to solve the problem?

EMG


Any suggestions? :-)

EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: SEND EMAIL
Posted: Wed Apr 03, 2013 06:01 PM

Enrico,

I have not seen such a problem. Are you getting error messages? Or, do you mean that some PCs have errors and some do not?

It could be the server. I have occasional server problems even with big email systems like Hotmail, AOL, etc. even with Outlook Express.

Perhaps you could put in a routine so that if it errors out when attempting to send, it tries again in 10 seconds--maybe a couple of times.

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: SEND EMAIL
Posted: Wed Apr 03, 2013 06:17 PM
James,

James Bott wrote:Enrico,

I have not seen such a problem. Are you getting error messages?


It seems not.

James Bott wrote:Or, do you mean that some PCs have errors and some do not?


No, the behavior is erratic on the same PC.

James Bott wrote:It could be the server. I have occasional server problems even with big email systems like Hotmail, AOL, etc. even with Outlook Express.

Perhaps you could put in a routine so that if it errors out when attempting to send, it tries again in 10 seconds--maybe a couple of times.

Regards,
James


Thank you, I will try.

EMG
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: SEND EMAIL
Posted: Wed Apr 03, 2013 07:11 PM

Enrico;

Are you sending multiple emails?

I'm using tsmtp on one of my apps quite a bit. Its working quite well for me. This particular app sends over 300 emails per day with .zip attachments. Remember TSMTP does not do SSL. Show me the code. Maybe I can help.

Reinaldo.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: SEND EMAIL
Posted: Wed Apr 03, 2013 08:14 PM
Reinaldo,

reinaldocrespo wrote:Enrico;

Are you sending multiple emails?


Yes, but the erratic behavior is the same with a single email.

reinaldocrespo wrote:I'm using tsmtp on one of my apps quite a bit. Its working quite well for me. This particular app sends over 300 emails per day with .zip attachments. Remember TSMTP does not do SSL. Show me the code. Maybe I can help.


The code is the one already reported here and in other threads (CDOSYS).

EMG
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: SEND EMAIL
Posted: Wed Apr 03, 2013 08:31 PM
CDOSYS and TSMTP are not the same. I have been using TSMTP. I once tried CDOSYS, but had sporadic errors and was never able to figure out, or did not spend enough time debuggin.

Here is my code using TSMTP, there are references to other objects, but I'm sure you can follow the code:

Code (fw): Select all Collapse
//-----------------------------------------------------------------------
METHOD SendViaEMail( oDbf, oPthRep ) CLASS TMpMailApp
   LOCAL aEmails := HB_ATOKENS( oDbf:Send_To, iif( ";" $ oDbf:Send_To, ";", "," ) )
   LOCAL oDoc      := ::oProcess:Getodbf( "doctors" )
   LOCAL cZipFile  := Temp_Name( "zip" )
   LOCAL cPass, oMail, oTmp
   LOCAL aFiles    := { oPthRep:cPdfFile }
   LOCAL cPathNo := oDbf:PathNo
   LOCAL nQueue  := oDbf:Queue
   LOCAL cSendTo := oDbf:Send_To

   IF oPthRep:isJpg  ;AADD( aFiles, oPthRep:cJpgFile )  ;ENDIF
   IF oPthRep:IsTiff ;AADD( aFiles, oPthRep:cTifFile)   ;ENDIF
   IF oPthRep:isHtml ;AADD( aFiles, oPthRep:cHtmlFile ) ;ENDIF
   IF oPthRep:isRtf  ;AADD( aFiles, oPthRep:cRtfFile )  ;ENDIF

   AEVAL( aEmails, { |e,n| aEmails[ n ] := ALLTRIM( e ) } )

   oDoc:Seek( oDbf:Doc_id )   ;iif( oDoc:Found(), oDoc:Load(), oDoc:Blank() )

   cPass   := ALLTRIM( IIF( oDoc:fieldexist( "password" ) .AND. ;
                     !EMPTY( oDoc:VarPassword ), ;
                     oDoc:VarPassword, oDbf:Doc_id ) )

   IF !hb_zipFile( cZipFile, aFiles, 9,,.t., cPass, .f., .f., .t.  )

      AEVAL( aFiles, { |e| fErase( e ) } )
      ferase( cZipFile )
      Logfile( "PtheMailsErrors.log", { "Error Creating .zip for case:", oDbf:PathNo } )

      RETURN NIL 

   ENDIF

   oMail := TMySmtp():New( ::cIp, ::nPort, ::lAuth, ::cUserName, ::cUserPass )
   oMail:cReplyTo := ::cSender
   oMail:nGMT := TimeZone() //-5   // Atlantic Standard Time (GMT -05:00)

   oMail:aAttachments := aFiles    //save file names to erase later
   
   oMail:oSocket:lDebug := ::lDebug
   oMail:oSocket:cLogFile := "smtp.log"
   oMail:nDelay := ::nDelay

   oMail:bConnecting   := { || iif( oMail:oSocket:lDebug,;
      logfile( oMail:oSocket:cLogFile, { cPathNo, "Connecting to SMTP server " + ::cSmtpServer } ), ) }

   oMail:bConnected   := { || iif( oMail:oSocket:lDebug, ;
      logfile( oMail:oSocket:cLogFile, { cpathNo, "Sending eMail Via " + ::cSmtpServer } ), ) }

   oMail:bDone := { || MailWasSent( cPathNo, nQueue, cSendto ),;
            LogSuccessIntoAuditLog( cPathNo, cSendto ),;
            fErase( cZipFile ),;
            AEVAL( oMail:aAttachments, { |e| ferase( e ) } ),;
            oMail:End(), ;
            oMail := Nil,;
            AEVAL( aFiles, { |e| fErase( e ) } ) }

   oMail:bFailure := { || IncAttempts( cPathNo, nQueue, cSendto ) ,;
            fErase( cZipFile ),;
            AEVAL( oMail:aAttachments, { |e| ferase( e ) } ),;
            iif( oMail != Nil .and. oMail:oSocket:lDebug, ;
                  logfile( oMail:oSocket:cLogFile, { "Failure to send email" } ), ),;
            iif( oMail != Nil, ( oMail:end(), oMail := Nil ), ) }


   oMail:SendMail( ::cSender, aEmails,                   ;
      "Pathology report attached intended for " +                                              ;
        alltrim( StrCapFirst( oDoc:Last ) ) + ", " + alltrim( StrCapFirst( oDoc:First ) )+      ;
        ".  Please use your password to open zipped file." + Chr( 13 ) + Chr( 12 ) +             ;
      "The information contained in this e-mail is privileged and confidential, intended only for the use of "+;
      "the individual or entity named above.  If the reader of this message is not the intended recipient, "+;
      "you are hereby notified that any dissemination, distribution or copy of this information is strictly "+;
      "prohibited.",    ;// Msg Text
      "Pathology Report", ;   // Subject
      { cZipFile },,, .t.  ) // attached files

RETURN NIL


That is working quite well for me. Hope it helps,


Reinaldo.
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: SEND EMAIL
Posted: Wed Apr 03, 2013 08:38 PM

Enrico,

Ah, I thought you were using the FW native TSMTP class.

Is it erroring out during configuration or during sending? If during sending, you might try adding a sysrefresh() just after the :Update() during the configuration.

How often is it erroring out? Once every ten times or? When it errors out, and you immediately try resending the same email does it go through?

If you send the same email 10-20 times does it go sometimes and not others?

Is it only erroring out when there is an attachment?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: SEND EMAIL
Posted: Wed Apr 03, 2013 08:42 PM

Reinaldo,

thank you, I'll try it.

EMG

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: SEND EMAIL
Posted: Wed Apr 03, 2013 08:50 PM
James,

James Bott wrote:Enrico,

Ah, I thought you were using the FW native TSMTP class.

Is it erroring out during configuration or during sending?


During sending.

James Bott wrote:If during sending, you might try adding a sysrefresh() just after the :Update() during the configuration.


Great suggestion! I'm going to try it, thank you!

James Bott wrote:How often is it erroring out? Once every ten times or?


Hard to say... :-)

James Bott wrote:When it errors out, and you immediately try resending the same email does it go through?


Yes.

James Bott wrote:If you send the same email 10-20 times does it go sometimes and not others?


Yes.

James Bott wrote:Is it only erroring out when there is an attachment?


I tested it with attachments.

EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: SEND EMAIL
Posted: Thu Apr 04, 2013 12:39 AM

Enrico,

OK, I think my original suggestion will be the best solution. When it errors, trap the error, and do a repeat send a few times until it goes through, or completes the cycle. Once it is automated, most of the emails will probably be sent without human intervention.

I did this type of thing a long time ago when I was sending automated faxes. It worked great.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: SEND EMAIL
Posted: Thu Apr 04, 2013 12:45 PM
James Bott wrote:Enrico,

OK, I think my original suggestion will be the best solution. When it errors, trap the error, and do a repeat send a few times until it goes through, or completes the cycle. Once it is automated, most of the emails will probably be sent without human intervention.

I did this type of thing a long time ago when I was sending automated faxes. It worked great.

James


I don't like it very much because I still don't know what the error is so I can't trap it.

EMG
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: SEND EMAIL
Posted: Thu Apr 04, 2013 01:25 PM

Enrico,

did you try hb_SendMail function? I´ve been successfully sending mails with attachments from gmail accounts (TLS/SSL) for a while now.

Regards,



André Dutheil

FWH 13.04 + HB 3.2 + MSVS 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: SEND EMAIL
Posted: Thu Apr 04, 2013 01:28 PM

Yes, I tried it but I found it very slow.

EMG