You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.5 KiB
61 lines
2.5 KiB
using API_NetFramework.Controllers;
|
|
using API_NetFramework.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlTypes;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Security.Cryptography;
|
|
using System.Web.Http;
|
|
using System.Web.Management;
|
|
|
|
namespace OnDocAPI_NetFramework.Controllers
|
|
{
|
|
public class MailController : ApiController
|
|
{
|
|
string tokenfunction = "Mail";
|
|
|
|
[HttpGet]
|
|
[Route("API/SendMail")]
|
|
public IHttpActionResult SendMail(string empfaenger, string betreff, string message, string dokumentid, string ondoclink)
|
|
{
|
|
|
|
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 (!empfaenger.ToUpper().Contains("@TKB.CH"))
|
|
{
|
|
return Content(HttpStatusCode.Forbidden, empfaenger + ": Email nicht bei der TKB - Mail nicht versandt");
|
|
}
|
|
string s = "";
|
|
try
|
|
{
|
|
s = System.Configuration.ConfigurationManager.AppSettings["MailParam"];
|
|
|
|
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";
|
|
StreamWriter writer = new StreamWriter(tmpfile);
|
|
writer.Write(s);
|
|
writer.Close();
|
|
writer.Dispose();
|
|
System.Diagnostics.Process.Start("powershell.exe", tmpfile);
|
|
APILogging.Log((HttpRequestMessage)Request, "Mail Versand: " + s, LogLevelType.Debug);
|
|
//return Content(HttpStatusCode.OK, "Mail versand noch nicht implementiert");
|
|
return Content(HttpStatusCode.OK, empfaenger + ": Mail versandt");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Mail Versand NOK: " + e.Message+" " + s, LogLevelType.Debug);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|