updates
parent
ad4b18237c
commit
8ac3613937
|
|
@ -143,6 +143,11 @@ namespace Bremen_ESG.Controllers
|
|||
public async Task<ActionResult> Esg_Mail(IFormCollection obj) {
|
||||
result ret = new result();
|
||||
|
||||
string company = obj["company"].ToString();
|
||||
string name = obj["name"].ToString();
|
||||
string job = obj["job"].ToString();
|
||||
string needs = obj["needs"].ToString();
|
||||
string other = obj["other"].ToString();
|
||||
string target_email = obj["email"].ToString();
|
||||
string target_link = obj["link"].ToString();
|
||||
|
||||
|
|
@ -153,10 +158,14 @@ namespace Bremen_ESG.Controllers
|
|||
err_msg += "無有效結果連結\n";
|
||||
}
|
||||
|
||||
if (GlobalClass.isEmail(target_email) == false)
|
||||
if (target_email != "")
|
||||
{
|
||||
err_msg += "無有效Email\n";
|
||||
if (GlobalClass.isEmail(target_email) == false)
|
||||
{
|
||||
err_msg += "無有效Email\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (err_msg != "")
|
||||
{
|
||||
|
|
@ -167,6 +176,24 @@ namespace Bremen_ESG.Controllers
|
|||
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||
}
|
||||
|
||||
|
||||
string ownHtml = "";
|
||||
ownHtml += "<h2>有人填寫ESG快速檢測通知信</h2>";
|
||||
ownHtml += "<br/>1.企業名稱:" + company;
|
||||
ownHtml += "<br/>2.聯絡人姓名:" + name;
|
||||
ownHtml += "<br/>3.聯絡人email:" + target_email;
|
||||
ownHtml += "<br/>4.聯絡人職稱:" + job;
|
||||
ownHtml += "<br/>5.已知ESG需求:" + needs;
|
||||
ownHtml += "<br/> 其他 >>> " + other;
|
||||
ownHtml += "<br/>6.檢測結果:<a href='" + target_link + "'>檢測結果頁</a>";
|
||||
|
||||
//建立AlternativeView
|
||||
var altView2 = AlternateView.CreateAlternateViewFromString(ownHtml, null, "text/html");
|
||||
//將圖檔資源加入AlternativeView
|
||||
|
||||
|
||||
await SendEsgResultOwnAsync(altView2);
|
||||
|
||||
string html = $@"";
|
||||
|
||||
string fullPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/email_pic/email_footer.jpg");
|
||||
|
|
@ -235,16 +262,24 @@ namespace Bremen_ESG.Controllers
|
|||
html += "</table>";
|
||||
html += "</body>";
|
||||
|
||||
//建立AlternativeView
|
||||
var altView = AlternateView.CreateAlternateViewFromString(html, null, "text/html");
|
||||
//將圖檔資源加入AlternativeView
|
||||
altView.LinkedResources.Add(res);
|
||||
|
||||
await SendEsgResultMailAsync(altView, target_email);
|
||||
if (target_email != "") {
|
||||
//建立AlternativeView
|
||||
var altView = AlternateView.CreateAlternateViewFromString(html, null, "text/html");
|
||||
//將圖檔資源加入AlternativeView
|
||||
altView.LinkedResources.Add(res);
|
||||
|
||||
await SendEsgResultMailAsync(altView, target_email);
|
||||
|
||||
ret.ret = "yes";
|
||||
|
||||
ret.message = "已寄送結果通知信至" + target_email;
|
||||
}
|
||||
else {
|
||||
ret.ret = "yes";
|
||||
ret.message = "無Email,無法寄送結果通知信";
|
||||
}
|
||||
|
||||
ret.ret = "yes";
|
||||
|
||||
ret.message = "已寄送結果通知信至" + target_email;
|
||||
|
||||
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||
}
|
||||
|
|
@ -266,6 +301,40 @@ namespace Bremen_ESG.Controllers
|
|||
|
||||
}
|
||||
|
||||
public async Task SendEsgResultOwnAsync(AlternateView altView)
|
||||
{
|
||||
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
|
||||
client.Host = GlobalClass.appsettings("MailServer:smtp_host");
|
||||
client.Port = int.Parse(GlobalClass.appsettings("MailServer:smtp_port"));
|
||||
client.EnableSsl = true;
|
||||
client.Credentials = new NetworkCredential(
|
||||
GlobalClass.appsettings("MailServer:smtp_username"),
|
||||
GlobalClass.appsettings("MailServer:smtp_password")
|
||||
);
|
||||
|
||||
var mail = new MailMessage();
|
||||
mail.IsBodyHtml = true;
|
||||
|
||||
mail.AlternateViews.Add(altView);
|
||||
mail.To.Add("queenie@bremen.com.tw,sunny.lin@bremen.com.tw");
|
||||
|
||||
mail.From = new MailAddress(GlobalClass.appsettings("MailServer:smtp_username"), "用戶ESG快速檢測結果", System.Text.Encoding.UTF8);
|
||||
mail.Subject = "用戶ESG快速檢測結果";
|
||||
await client.SendMailAsync(mail).ContinueWith(task =>
|
||||
{
|
||||
if (task.IsFaulted)
|
||||
{
|
||||
Console.WriteLine("Error sending email: " + task.Exception);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Email sent successfully.");
|
||||
}
|
||||
});
|
||||
|
||||
client.Dispose();
|
||||
}
|
||||
|
||||
public async Task SendEsgResultMailAsync(AlternateView altView, string toEmail) {
|
||||
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
|
||||
client.Host = GlobalClass.appsettings("MailServer:smtp_host");
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ builder.Services.AddCors(options =>
|
|||
options.AddPolicy(name: "any", builder =>
|
||||
{
|
||||
builder.WithOrigins("https://www.bremen.com.tw",
|
||||
"https://bremen.com.tw")
|
||||
"https://bremen.com.tw", "https://preview.bremen.com.tw",
|
||||
"http://970px.dscloud.me/")
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue