sugoi internally added

This commit is contained in:
pvincent
2021-08-27 17:54:17 +04:00
parent ef31c26525
commit 445448f43b
100 changed files with 8758 additions and 23 deletions
+45
View File
@@ -0,0 +1,45 @@
package sugoi.mail;
import sugoi.mail.IMail;
import sugoi.mail.IMailer;
/**
* A Debug Mailer to use in dev environment :
* logs the emails in the Error table + write html files in tmp folder
*
* @author fbarbut
*/
class DebugMailer implements IMailer
{
public function new() {}
public function init(?c:Dynamic):IMailer{
return this;
}
public function send(m:sugoi.mail.IMail,?params:Dynamic,?callback:MailerResult->Void):Void{
//log in the Error table
var t = new StringBuf();
t.add("to:" + m.getRecipients()+"\n");
t.add("subject:" + m.getSubject()+"\n");
t.add("body:" + m.getHtmlBody()+"\n");
App.current.logError( "[DEBUG] Email sent to " + m.getRecipients(), t.toString() );
//log in an html file
var tmpDir = sugoi.Web.getCwd() + "../tmp/";
if ( !sys.FileSystem.exists(tmpDir) ) sys.FileSystem.createDirectory(tmpDir);
var dest = m.getRecipients()[0].email;
sys.io.File.saveContent( tmpDir + dest+"-"+Date.now().toString().substr(0,10)+ "-"+ m.getSubject() + ".html" , m.getHtmlBody() );
//callback
if (callback != null){
var map = new MailerResult();
for ( u in m.getRecipients() ){
map.set( u.email , Success(Sent) );
}
callback(map);
}
}
}