pvincent
3 years ago
6 changed files with 224 additions and 137 deletions
-
53src/App.hx
-
4src/controller/Cron.hx
-
11src/controller/Messages.hx
-
144src/sugoi/db/BufferedMail.hx
-
49src/sugoi/mail/BufferedMailer.hx
-
100src/sugoi/mail/SendEmailMailer.hx
@ -0,0 +1,100 @@ |
|||||
|
package sugoi.mail; |
||||
|
|
||||
|
import tink.core.Future; |
||||
|
import tink.core.Noise; |
||||
|
import sugoi.mail.IMailer; |
||||
|
import smtpmailer.Address; |
||||
|
|
||||
|
typedef SmtpInfo = { |
||||
|
host:String, |
||||
|
port:Int, |
||||
|
auth:{ |
||||
|
username:String, password:String |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Send emails thru OS command `sendemail` |
||||
|
* requires: `apt install sendemail libio-socket-ssl-perl libnet-ssleay-perl` |
||||
|
*/ |
||||
|
class SendEmailMailer implements IMailer { |
||||
|
var m:SmtpInfo; |
||||
|
|
||||
|
public function new() {} |
||||
|
|
||||
|
public function init(?conf:{ |
||||
|
smtp_host:String, |
||||
|
smtp_port:Int, |
||||
|
smtp_user:String, |
||||
|
smtp_pass:String |
||||
|
}):IMailer { |
||||
|
var mailer:SendEmailMailer = new SendEmailMailer(); |
||||
|
mailer.m = { |
||||
|
host: conf.smtp_host, |
||||
|
port: conf.smtp_port, |
||||
|
auth: { |
||||
|
username: conf.smtp_user, |
||||
|
password: conf.smtp_pass |
||||
|
} |
||||
|
}; |
||||
|
return mailer; |
||||
|
} |
||||
|
|
||||
|
public function send(e:sugoi.mail.IMail, ?params:Dynamic, ?callback:MailerResult->Void) { |
||||
|
var mailServer = "mail1.zourit.net"; |
||||
|
var mailPort = 587; |
||||
|
|
||||
|
var fromName = "John Doe"; |
||||
|
var fromEmail = "no-reply@comptoirduvrac.re"; |
||||
|
|
||||
|
var args = [ |
||||
|
"-f", |
||||
|
'${fromName} <${fromEmail}>', |
||||
|
"-s", |
||||
|
"mail1.zourit.net:587", |
||||
|
"-t", |
||||
|
"pvincent@comptoirduvrac.re", |
||||
|
// "-bcc", "pvincent974@gmail.com,pvincent974@laposte.net", |
||||
|
"-u", |
||||
|
e.getSubject(), |
||||
|
"-m", |
||||
|
"alors tout va bien", |
||||
|
"-xu", |
||||
|
"postmaster@comptoirduvrac.re", |
||||
|
"-xp", |
||||
|
"QqQeAPT6EpoK" |
||||
|
]; |
||||
|
|
||||
|
App.log('args=${args.join(" ")}'); |
||||
|
|
||||
|
var exitCode = Sys.command("sendemail", args); |
||||
|
// var exitCode = 0; |
||||
|
|
||||
|
if (exitCode == 0) |
||||
|
App.log('email from="${e.getSender().name} <${e.getSender().email}"> subject=<${e.getSubject()}> successfully sent'); |
||||
|
else |
||||
|
App.log('ERROR: email from="${e.getSender().name} <${e.getSender().email}"> subject=<${e.getSubject()}> cannot be sent'); |
||||
|
|
||||
|
// sys.io.File.saveContent('/tmp/my_file.json', "CONTENT"); |
||||
|
|
||||
|
// var surprise = m.send({ |
||||
|
// subject: e.getSubject(), |
||||
|
// from: new Address({address: e.getSender().email}), |
||||
|
// to: Lambda.array(Lambda.map(e.getRecipients(), function(x) return new Address({address: x.email}))), |
||||
|
// headers: e.getHeaders(), |
||||
|
// content: { |
||||
|
// text: e.getTextBody(), |
||||
|
// html: e.getHtmlBody() |
||||
|
// } |
||||
|
// }); |
||||
|
|
||||
|
if (callback != null) { |
||||
|
var map = new MailerResult(); |
||||
|
if (exitCode == 0) |
||||
|
map.set("*", Success(Sent)); |
||||
|
else |
||||
|
map.set("*", Failure(HardBounce)); |
||||
|
callback(map); |
||||
|
} |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue