diff --git a/src/xvaga/xvt.h b/src/xvaga/xvt.h index 8ac6a6b0a..76f677344 100755 --- a/src/xvaga/xvt.h +++ b/src/xvaga/xvt.h @@ -583,11 +583,14 @@ XVTDLL BOOLEAN xvt_url_get(const char * url, const char * path, const XVTDLL void xvt_set_mail_params(const char * smtp, const char * port, const char * user, const char * pass, const char * from); // Send email using normal methods -XVTDLL BOOLEAN xvt_mail_send(const char* to, const char* cc, const char* ccn, - const char* subject, const char* msg, const char* attach, short flags); // 0x1=UI; 0x2=Receipt + // flags 0x1=UI; 0x2=Receipt +XVTDLL BOOLEAN xvt_mail_send(const char* to, const char* cc, const char* ccn, const char* subject, + const char* msg, const char* attach, short flags); // Send email using Microsoft Powershell XVTDLL BOOLEAN xvt_powermail_send(const char* to, const char* cc, const char* ccn, const char* subject, const char* msg, const char* attach, short flags, const char* usr); // 0x1=UI; 0x2=Receipt +XVTDLL BOOLEAN xvt_wx_mail_send(const char* to, const char* cc, const char* ccn, const char* subject, + const char* msg, const char* attach, short flags); XVTDLL short xvt_mail_installed(); XVTDLL void xvt_btn_set_images(WINDOW win, XVT_IMAGE up, XVT_IMAGE down); diff --git a/src/xvaga/xvtmail.cpp b/src/xvaga/xvtmail.cpp index 5529a1a04..b2681e21a 100755 --- a/src/xvaga/xvtmail.cpp +++ b/src/xvaga/xvtmail.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include static wxString GetMailParam(const char* key, const char* def = "") @@ -69,7 +71,7 @@ void xvt_set_mail_params(const char * smtp, const char * port, const char * user if (user && *user) __user = _strdup(user); if (pass && *pass) - __pass = _strdup(from); + __pass = _strdup(pass); } static bool GetMailParams(wxString& smtp, wxString& port, wxString& user, wxString& pass, wxString& from) @@ -425,7 +427,7 @@ BOOLEAN xvt_powermail_send(const char* to, const char* cc, const char* ccn, // Controllo che Windows sia almeno 8 e che riesca a ricevere i parametri E-mail if(xvt_sys_get_os_version() < XVT_WS_WIN_7 || !GetMailParams(server, port, user, password, from)) - xvt_mail_send(to, cc, ccn, subject, msg, attach, flags); + xvt_mail_send(to, cc, ccn, subject, msg, attach, flags); wxString str_to(to); @@ -503,7 +505,7 @@ BOOLEAN xvt_powermail_send(const char* to, const char* cc, const char* ccn, file.Write("$CC = "); file.Write(str_cc); file.Write("\n"); } - if (has_ccnsend()) + if (hasccn || has_ccnsend()) { wxString str_ccn(from); buildPSArray(str_ccn); @@ -517,7 +519,7 @@ BOOLEAN xvt_powermail_send(const char* to, const char* cc, const char* ccn, //TODO same per from e to //mettere un flag nella mask per decidere se mettere in CC o in CCn - if (hascc == true) + /*if (hascc == true) { file.Write( "foreach($i in $CC)\n" @@ -531,7 +533,7 @@ BOOLEAN xvt_powermail_send(const char* to, const char* cc, const char* ccn, "foreach($i in $Bcc)\n" "{ $message.Bcc.Add($i)}\n" ); - } + } */ file.Write( @@ -571,18 +573,21 @@ BOOLEAN xvt_powermail_send(const char* to, const char* cc, const char* ccn, "catch\n" "{\n" " write-host \"E-Mail not sent\" ; \n" - " $exitCode = 1 \n" - " exit $exitCode \n" + " write-host $_.Exception.Message ;\n" + " $exitCode = 1 \n" + " exit $exitCode \n" "}\n" ); file.Close(); - wxString command("powershell.exe -File "); + wxString command("powershell.exe -File "); //una volta scritto lo scritp ps1 cos'è che lo runna? Dove vinene aperta la PowerShell? // al momento lo script generato da campo funziona se runnato direttamente da powershell command << powerFile; + FILE *f; + fopen_s(&f, "maillog.log", "w"); fprintf(f, "Comando %s\n", (const char*)command); int exit = xvt_sys_execute(command, true, true); @@ -590,3 +595,60 @@ BOOLEAN xvt_powermail_send(const char* to, const char* cc, const char* ccn, fclose(f); return exit == 0; } + +BOOLEAN xvt_wx_mail_send(const char* to, const char* cc, const char* ccn, + const char* subject, const char* msg, + const char* attach, short flags) +{ + wxString server, port, user, password, from; + GetMailParams(server, port, user, password, from); + bool ui = (flags & 0x1) != 0; + wxSMTP * Smtp = new wxSMTP(nullptr); + wxString str_to(to); + bool ok = true; + + if (ui) + { + wxEmailDlg dlg; + + dlg._strEmail = str_to; + if (dlg.ShowModal() == wxID_OK) + str_to = dlg._strEmail; + } + + wxStringTokenizer tokTo(str_to, _T(";")); + wxEmailMessage * Msg = new wxEmailMessage(subject, msg, from); + +// da trovare Msg->m_query_receipt = flags & 0x2; + while (tokTo.HasMoreTokens()) + Msg->AddTo(tokTo.GetNextToken()); + if (attach && *attach) + { + wxStringTokenizer tokAttach(attach, _T(";")); + while (tokAttach.HasMoreTokens()) + Msg->AddFile(tokAttach.GetNextToken()); + } + if (cc && *cc) + { + wxStringTokenizer Tok(cc, _T(";")); + while (Tok.HasMoreTokens()) + Msg->AddCc(Tok.GetNextToken()); + } + if (ccn && *ccn) + { + wxStringTokenizer Tok(ccn, _T(";")); + while (Tok.HasMoreTokens()) + Msg->AddBcc(Tok.GetNextToken()); + } + + int service = atoi(port); + + if (service == 0) + service = 25; + Smtp->SetHost(server, service, from, password); + Smtp->Send(Msg); + Smtp->SendData(); + delete Msg; + delete Smtp; + return ok; +}