#!/usr/bin/env gbs3
' Gambas module file

USE "gb.db", "gb.net.smtp"

Private hcon As New Connection
Private hTim as Timer
Public Sub Main()
  Application.Daemon = True
  hTim = new timer as "Timer1"
  hTim.Delay = 60000
  hTim.Start
End

Public sub Timer1_Timer()
  Dim hsmtp As Smtpclient
  Dim hResMails As Result
  Dim s As String
  'print "coucou"
  'return
  'Définir la connection
  hcon.type = "mysql"
  hCon.host = "localhost"
  hcon.login = "*****"
  hCon.password = "***"
  hcon.name = "MyDB"

  hResMails = db.exec("SELECT * FROM emails")

  For Each hResMails
    hsmtp = New SmtpClient
    hsmtp.Host = "mail.toile-libre.org"
    hsmtp.User = "gf_i...@gambasforge.org"
    hsmtp.Password = "***"
    hsmtp.Port = 587
    hsmtp.From = hsmtp.User
    For Each s In Split(hResMails!to)
        hsmtp.To.Add(s)
    Next
    For Each s In Split(hResMails!cc)
      hsmtp.Cc.Add(s)
    Next
    For Each s In Split(hResMails!bcc)
      hsmtp.bcc.Add(s)
    Next
    hsmtp.Subject = iif(hResMails!sujet, hResMails!sujet, "nosubject")
    hsmtp.Add(hResMails!message, "text/plain")
    if hResMails!message_html Then hsmtp.Add(hResMails!message_html,
"text/html")
    hsmtp.Send()
  Next
  If hResMails.count = 0 Then Return
  hResMails.MoveLast()
  db.Exec("DELETE FROM emails WHERE id<=&1", hResMails!id)

Catch
    Shell "echo " & Error.Backtrace.Join("\n") & Error.Text & Error.Where &
" >> mailerror.log"

End


This is a script deamon i wrote for the gambasforge, that send db stored
mail every 1 minute to all the site users. (i use bcc for that)
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to