added methode3
This commit is contained in:
@ -2,6 +2,8 @@
|
||||
using EmailServiceApi.Services;
|
||||
|
||||
using EmailServiceApi.Models;
|
||||
using System.Net.Mail;
|
||||
using System.Net;
|
||||
|
||||
namespace EmailServiceApi.Controllers
|
||||
{
|
||||
@ -116,8 +118,46 @@ 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 string SmtpServer { get; set; }
|
||||
@ -126,4 +166,4 @@ namespace EmailServiceApi.Controllers
|
||||
// public string Subject { 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
|
||||
{
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user