Re: [Gambas-user] send e-mail out of gambas
Brought to you by:
gambas
From: Fabien B. <gam...@gm...> - 2012-04-30 12:43:18
|
#!/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...@ga..." 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) |