HomeController.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.Extensions.Logging;
  8. using FMSAdmin.Models;
  9. using System.Security.Claims;
  10. using Microsoft.AspNetCore.Authentication;
  11. using Microsoft.AspNetCore.Authentication.Cookies;
  12. using Microsoft.AspNetCore.Authorization;
  13. using FMSAdmin.Data;
  14. using System.Net.Mail;
  15. using System.Net;
  16. using FMSAdmin.Helpers;
  17. using SelectPdf;
  18. namespace FMSAdmin.Controllers {
  19. [ApiController]
  20. [ApiVersion("1")]
  21. [Route("api")]
  22. public class HomeController : Controller {
  23. private readonly ILogger<HomeController> _logger;
  24. private readonly FMSContext _context;
  25. private readonly StorageHelper _storage;
  26. public HomeController(
  27. ILogger<HomeController> logger,
  28. FMSContext context,
  29. StorageHelper storage
  30. ) {
  31. _logger = logger;
  32. _context = context;
  33. _storage = storage;
  34. }
  35. [HttpGet]
  36. public IActionResult Index() {
  37. return Content("api server");
  38. }
  39. [HttpGet("[action]")]
  40. public IActionResult EmailTest() {
  41. // 이메일 테스트
  42. using (var message = new MailMessage()) {
  43. // 받는사람
  44. message.To.Add(new MailAddress("테스트@gmail.com", "테스트"));
  45. // 보내는사람
  46. message.From = new MailAddress("hdc.icontrols.rnd1@gmail.com", "FMS");
  47. //message.CC.Add(new MailAddress("cc@email.com", "CC Name"));
  48. //message.Bcc.Add(new MailAddress("bcc@email.com", "BCC Name"));
  49. message.Subject = "이메일 인증 테스트";
  50. message.Body = "코드는 2390423 입니다.";
  51. message.IsBodyHtml = true;
  52. var smtp = new SmtpClient {
  53. Host = "smtp.gmail.com",
  54. Port = 587,
  55. EnableSsl = true,
  56. DeliveryMethod = SmtpDeliveryMethod.Network,
  57. Credentials = new NetworkCredential("hdc.icontrols.rnd1@gmail.com", "pwrd12#$"),
  58. Timeout = 20000
  59. };
  60. smtp.Send(message);
  61. }
  62. return Content(":)");
  63. }
  64. }
  65. }