added methode3
This commit is contained in:
parent
bb57113461
commit
7584706123
@ -2,6 +2,8 @@
|
|||||||
using EmailServiceApi.Services;
|
using EmailServiceApi.Services;
|
||||||
|
|
||||||
using EmailServiceApi.Models;
|
using EmailServiceApi.Models;
|
||||||
|
using System.Net.Mail;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
namespace EmailServiceApi.Controllers
|
namespace EmailServiceApi.Controllers
|
||||||
{
|
{
|
||||||
@ -116,6 +118,44 @@ namespace EmailServiceApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[HttpPost("Methode3")]
|
||||||
|
|
||||||
|
public ActionResult<string> SendEmailAsync(EmailRequest3 emailRequest, string smtpServer = "smtp.gmail.com", int smtpPort = 587, string? smtpUsername = "smtp User", string? smtpPassword = "smtp password", string? fromEmail = "from-email@domain.com", string? ToAddress= "to-email@domain.com")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//string smtpServer = "smtp.gmail.com";
|
||||||
|
//int smtpPort = 587;
|
||||||
|
//string smtpUsername = "vijay.net33@gmail.com";
|
||||||
|
//string smtpPassword = "nmlzxgkhmafdxxul";
|
||||||
|
//string fromEmail = "vijay.net33@gmail.com";
|
||||||
|
|
||||||
|
using (MailMessage mail = new MailMessage())
|
||||||
|
{
|
||||||
|
mail.From = new MailAddress(fromEmail);
|
||||||
|
mail.To.Add(ToAddress);
|
||||||
|
mail.Subject = emailRequest.Subject;
|
||||||
|
mail.Body = emailRequest.Body;
|
||||||
|
|
||||||
|
using (SmtpClient smtp = new SmtpClient(smtpServer, smtpPort))
|
||||||
|
{
|
||||||
|
smtp.Credentials = new NetworkCredential(smtpUsername, smtpPassword);
|
||||||
|
smtp.EnableSsl = true;
|
||||||
|
smtp.SendMailAsync(mail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok("Email sent successfully.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, $"Failed to send email: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//public class EmailRequest
|
//public class EmailRequest
|
||||||
@ -126,4 +166,4 @@ namespace EmailServiceApi.Controllers
|
|||||||
// public string Subject { get; set; }
|
// public string Subject { get; set; }
|
||||||
// public string Body { get; set; }
|
// public string Body { get; set; }
|
||||||
//}
|
//}
|
||||||
}
|
|
||||||
|
6
Controllers/IHttpActionResult.cs
Normal file
6
Controllers/IHttpActionResult.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace EmailServiceApi.Controllers
|
||||||
|
{
|
||||||
|
public interface IHttpActionResult
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.7.34031.279
|
VisualStudioVersion = 17.7.34031.279
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmailServiceApi", "EmailServiceApi.csproj", "{A4017F77-8FC9-4816-AF54-90B55F66BDE1}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmailServiceApi", "EmailServiceApi.csproj", "{A4017F77-8FC9-4816-AF54-90B55F66BDE1}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -20,5 +20,10 @@
|
|||||||
public string password { get; set; }
|
public string password { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class EmailRequest3
|
||||||
|
{
|
||||||
|
// public string ToAddress { get; set; }
|
||||||
|
public string Subject { get; set; }
|
||||||
|
public string Body { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
@ -89,5 +89,8 @@ namespace EmailServiceApi.Services
|
|||||||
// return $"Failed to send email: {ex.Message}";
|
// return $"Failed to send email: {ex.Message}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
docker-compose.yml
Normal file
11
docker-compose.yml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
email-service:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
environment:
|
||||||
|
ASPNETCORE_ENVIRONMENT: Development
|
||||||
|
ports:
|
||||||
|
- "9001:80"
|
Loading…
Reference in New Issue
Block a user