[Gambas-user] send e-mail out of gambas
Fabien Bodard
gambas.fr at ...626...
Mon Apr 30 14:43:11 CEST 2012
#!/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_info at ...2827..."
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)
More information about the User
mailing list