update 20250727
This commit is contained in:
@@ -16,6 +16,7 @@ using System.Configuration;
|
||||
using SecuringWebApiUsingApiKey.Middleware;
|
||||
using System.Text;
|
||||
using System.Net.Mail;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace OnDocAPI_NetFramework.Controllers
|
||||
{
|
||||
@@ -58,7 +59,7 @@ namespace OnDocAPI_NetFramework.Controllers
|
||||
if (Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][3]) == 0)
|
||||
{
|
||||
db = null;
|
||||
return Content(HttpStatusCode.OK, empfaenger + ": Mail gem. MA-Einstelung nicht zugestellt");
|
||||
return Content(HttpStatusCode.OK, empfaenger + ": Mail gem. MA-Einstellung nicht zugestellt");
|
||||
}
|
||||
empfaenger = db.dsdaten.Tables[0].Rows[0][0].ToString();
|
||||
|
||||
@@ -186,6 +187,63 @@ namespace OnDocAPI_NetFramework.Controllers
|
||||
return Content(HttpStatusCode.InternalServerError, e.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("API/SendHTMLMail")]
|
||||
public IHttpActionResult SendMailManual()
|
||||
{
|
||||
string result = Request.Content.ReadAsStringAsync().Result;
|
||||
Model.EMail email = new Model.EMail();
|
||||
email = JsonConvert.DeserializeObject<Model.EMail>(result);
|
||||
if (Regex.IsMatch(email.empfaenger, @"^\d+$") == false && !email.empfaenger.ToUpper().Contains("@TKB.CH"))
|
||||
{
|
||||
return Content(HttpStatusCode.Forbidden, email.empfaenger + ": Email nicht bei der TKB - Mail nicht versandt");
|
||||
}
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mailversand: " + email.empfaenger + "" + email.betreff, LogLevelType.Debug);
|
||||
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
||||
{
|
||||
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
||||
}
|
||||
email = JsonConvert.DeserializeObject<Model.EMail>(result);
|
||||
if (Regex.IsMatch(email.empfaenger, @"^\d+$") == false && !email.empfaenger.ToUpper().Contains("@TKB.CH"))
|
||||
{
|
||||
return Content(HttpStatusCode.Forbidden, email.empfaenger + ": Email nicht bei der TKB - Mail nicht versandt");
|
||||
}
|
||||
string s = "";
|
||||
|
||||
try
|
||||
{
|
||||
MailMessage mail = new MailMessage();
|
||||
SmtpClient SmtpServer = new SmtpClient();
|
||||
mail.To.Add(email.empfaenger);
|
||||
mail.From = new MailAddress("OnDoc@tkb.ch");
|
||||
mail.Subject = email.betreff;
|
||||
mail.IsBodyHtml = true;
|
||||
mail.Body = email.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: " + email.empfaenger, LogLevelType.Debug);
|
||||
return Content(HttpStatusCode.OK, email.empfaenger + ": Mail versandt");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mail Versand NOK: " + ex.Message + " " + email.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