FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Correo desatendido?
Posts: 3382
Joined: Fri Oct 07, 2005 08:20 PM

Correo desatendido?

Posted: Fri Jul 03, 2026 12:54 AM

Foreros:

Existe alguna forma de enviar correo de manera desatendida?, es decir que a cierta hora se envié un correo con un .ZIP adjunto.

Saludos y gracias por la orientación

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 890
Joined: Thu Dec 24, 2009 12:46 AM

Re: Correo desatendido?

Posted: Fri Jul 03, 2026 05:38 AM

Solamente preguntale a Gemini, en Google... (Free)

Usando MailGun:

FiveWin (the GUI library for Harbour/xHarbour/Clipper) can absolutely send unattended emails through Mailgun.Since FiveWin applications usually run as Windows desktop executables (.exe), you can use its built-in Internet features to make an HTTP POST request directly to the Mailgun API. This bypasses the need for local SMTP or Outlook.The FiveWin Source CodeYou can use the MSXML2.ServerXMLHTTP object inside FiveWin to send the email and the .ZIP attachment completely in the background without showing any windows to the user.harbour

#include "FiveWin.ch"

FUNCTION Main()
   LOCAL cDomain  := "YOUR_DOMAIN_NAME.com"
   LOCAL cApiKey  := "YOUR_MAILGUN_API_KEY"
   LOCAL cZipPath := "C:\backups\data.zip"
   

   SendMailgunEmail( cDomain, cApiKey, cZipPath )
RETURN NIL

FUNCTION SendMailgunEmail( cDomain, cApiKey, cZipPath )
   LOCAL oHttp, cUrl, cAuth, cBoundary, cPostData
   

   IF ! File( cZipPath )
      MsgInfo( "Error: ZIP file not found at " + cZipPath )
      RETURN .F.
   ENDIF

   cUrl := "https://mailgun.net" + cDomain + "/messages"
   

   // Mailgun requires Basic Auth (username is always "api")
   cAuth := "Basic " + hb_base64Encode( "api:" + cApiKey )
   

   // Generate a unique boundary for the multi-part form data (required for attachments)
   cBoundary := "----FiveWinBoundary" + ttos( datetime() )
   cBoundary := StrTran( cBoundary, " ", "" )
   cBoundary := StrTran( cBoundary, ":", "" )
   cBoundary := StrTran( cBoundary, "-", "" )

   // Build the raw HTTP multi-part payload
   cPostData := "--" + cBoundary + hb_eol()
   cPostData += 'Content-Disposition: form-data; name="from"' + hb_eol() + hb_eol()
   cPostData += "Automated System <system@" + cDomain + ">" + hb_eol()
   

   cPostData += "--" + cBoundary + hb_eol()
   cPostData += 'Content-Disposition: form-data; name="to"' + hb_eol() + hb_eol()
   cPostData += "recipient@example.com" + hb_eol()
   

   cPostData += "--" + cBoundary + hb_eol()
   cPostData += 'Content-Disposition: form-data; name="subject"' + hb_eol() + hb_eol()
   cPostData += "FiveWin Automated Backup" + hb_eol()
   

   cPostData += "--" + cBoundary + hb_eol()
   cPostData += 'Content-Disposition: form-data; name="text"' + hb_eol() + hb_eol()
   cPostData += "Please find attached the unattended backup file." + hb_eol()

   // Append the binary ZIP file
   cPostData += "--" + cBoundary + hb_eol()
   cPostData += 'Content-Disposition: form-data; name="attachment"; filename="' + cFileNoPath( cZipPath ) + '"' + hb_eol()
   cPostData += "Content-Type: application/zip" + hb_eol() + hb_eol()
   cPostData += memoread( cZipPath ) + hb_eol()
   cPostData += "--" + cBoundary + "--" + hb_eol()

   // Send the HTTP request
   TRY
      oHttp := CreateObject( "MSXML2.ServerXMLHTTP.6.0" )
      oHttp:Open( "POST", cUrl, .F. )
      oHttp:SetRequestHeader( "Authorization", cAuth )
      oHttp:SetRequestHeader( "Content-Type", "multipart/form-data; boundary=" + cBoundary )
      oHttp:Send( cPostData )
      

  // Optional log (visible only if you check it)
  IF oHttp:Status == 200
     // Success
     AltD() // Debug trace point or write to a local log.txt
  ELSE
     // Failed
     memowrit( "mailgun_error.log", oHttp:ResponseText )
  ENDIF
   CATCH
      memowrit( "mailgun_error.log", "Could not connect to Mailgun API" )
   END_TRY

RETURN NIL

Making it Unattended (No Human Interaction)Compile the code above into a standalone console or windowless executable (e.g., backup_mail.exe). It runs completely hidden without demanding user input.

=====>

Bayron Landaverry
NextXbase.com
(215)2226600 Philadelphia,PA, USA
MayaBuilders@gMail.com
Guatemala

FWH25.12--Harbour 3.0.0--MSVC--UEstudio 10.10
Windows 11

FiveWin, One line of code and it's done...

Posts: 3382
Joined: Fri Oct 07, 2005 08:20 PM

Re: Correo desatendido?

Posted: Sat Jul 04, 2026 03:47 AM

Bayrón:

Muchas gracias, lo voy a intentar.

Saludos

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero

Continue the discussion