update 20250226
This commit is contained in:
@@ -15,6 +15,7 @@ using System.Web.Management;
|
||||
using System.Configuration;
|
||||
using SecuringWebApiUsingApiKey.Middleware;
|
||||
using System.Text;
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace OnDocAPI_NetFramework.Controllers
|
||||
{
|
||||
@@ -22,9 +23,9 @@ namespace OnDocAPI_NetFramework.Controllers
|
||||
{
|
||||
string tokenfunction = "Mail";
|
||||
|
||||
[HttpGet]
|
||||
[Route("API/SendMail")]
|
||||
public IHttpActionResult SendMail(string MailID, string empfaenger, string betreff, string message, string dokumentid, string ondoclink, string absender, string bewilligungid)
|
||||
//[HttpGet]
|
||||
//[Route("API/SendPSMail")]
|
||||
private IHttpActionResult SendPSMail(string MailID, string empfaenger, string betreff, string message, string dokumentid, string ondoclink, string absender, string bewilligungid)
|
||||
{
|
||||
string connectionstring = StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["EDOKAConnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
|
||||
string URI = "";
|
||||
@@ -92,6 +93,8 @@ namespace OnDocAPI_NetFramework.Controllers
|
||||
s = s.Replace("$$empfaenger$$", empfaenger);
|
||||
s = s.Replace("$$betreff$$", betreff);
|
||||
s = s.Replace("$$body$$", message);
|
||||
|
||||
|
||||
string debugdir = System.Configuration.ConfigurationManager.AppSettings["DebugDir"];
|
||||
string tmpfile = debugdir + @"\Mail_" + DateTime.Now.ToString("yyyyMMdd_hhmmss") + ".ps1";
|
||||
System.IO.File.WriteAllText(tmpfile, s,new UTF8Encoding(true));
|
||||
@@ -110,5 +113,79 @@ namespace OnDocAPI_NetFramework.Controllers
|
||||
return Content(HttpStatusCode.InternalServerError, e.Message);
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("API/SendMail")]
|
||||
public IHttpActionResult SendMail(string MailID, string empfaenger, string betreff, string message, string dokumentid, string ondoclink, string absender, string bewilligungid)
|
||||
{
|
||||
string connectionstring = StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["EDOKAConnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
|
||||
string URI = "";
|
||||
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mailversand: " + empfaenger + "" + betreff, LogLevelType.Debug);
|
||||
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
||||
{
|
||||
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
||||
}
|
||||
|
||||
if (Regex.IsMatch(empfaenger, @"^\d+$") == false && !empfaenger.ToUpper().Contains("@TKB.CH"))
|
||||
{
|
||||
return Content(HttpStatusCode.Forbidden, empfaenger + ": Email nicht bei der TKB - Mail nicht versandt");
|
||||
}
|
||||
string s = "";
|
||||
DB db = new DB(connectionstring);
|
||||
try
|
||||
{
|
||||
db.clear_parameter();
|
||||
db.add_parameter("@mailid", MailID.ToString());
|
||||
db.add_parameter("@empf", empfaenger);
|
||||
db.add_parameter("@dokid", dokumentid);
|
||||
db.add_parameter("@absender", absender);
|
||||
db.add_parameter("@bewilligungid", bewilligungid);
|
||||
db.Get_Tabledata("sp_ondoc_maildaten", true, false);
|
||||
if (message == null) { message = ""; }
|
||||
if (betreff == null) { betreff = ""; }
|
||||
if (betreff == "") { betreff = db.dsdaten.Tables[0].Rows[0][1].ToString(); }
|
||||
if (message == "") { message = db.dsdaten.Tables[0].Rows[0][2].ToString(); }
|
||||
if (Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][3]) == 0)
|
||||
{
|
||||
db = null;
|
||||
return Content(HttpStatusCode.OK, empfaenger + ": Mail gem. MA-Einstelung nicht zugestellt");
|
||||
}
|
||||
empfaenger = db.dsdaten.Tables[0].Rows[0][0].ToString();
|
||||
db = null;
|
||||
|
||||
MailMessage mail = new MailMessage();
|
||||
SmtpClient SmtpServer = new SmtpClient();
|
||||
mail.To.Add(empfaenger);
|
||||
mail.From = new MailAddress("OnDoc@tkb.ch");
|
||||
mail.Subject = betreff;
|
||||
mail.IsBodyHtml = true;
|
||||
mail.Body = message;
|
||||
SmtpServer.Host = "smtp.tgcorp.ch";
|
||||
SmtpServer.Port = 25;
|
||||
SmtpServer.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
|
||||
try
|
||||
{
|
||||
SmtpServer.Send(mail);
|
||||
APILogging.Log((HttpRequestMessage)Request, "SMTPMail Versand: " + empfaenger, LogLevelType.Debug);
|
||||
return Content(HttpStatusCode.OK, empfaenger + ": Mail versandt");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mail Versand NOK: " + ex.Message + " " + empfaenger, LogLevelType.Debug);
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mail Versand NOK - Exception Inner: " + ex.InnerException, LogLevelType.Debug);
|
||||
}
|
||||
return Content(HttpStatusCode.InternalServerError, ex.Message);
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mail Versand NOK: " + e.Message + " " + s, LogLevelType.Debug);
|
||||
return Content(HttpStatusCode.InternalServerError, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user