Skip to content

Commit

Permalink
Merge pull request #3 from sherweb/InitialCommit
Browse files Browse the repository at this point in the history
Sendgrid added to the app
  • Loading branch information
asantossheweb authored Nov 4, 2024
2 parents e5be969 + f0e4985 commit b826e7b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 42 deletions.
79 changes: 37 additions & 42 deletions Xtkl.NceTransferWebhooks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,60 @@
using System.Net.Mail;
using SendGrid;
using SendGrid.Helpers.Mail;

var builder = WebApplication.CreateBuilder(args);

// Configure logging to capture detailed logs
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Logging.SetMinimumLevel(LogLevel.Debug);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI();

app.UseHttpsRedirection();


app.MapPost("/transfer-completed", async (CompleteTransferDto request) =>
app.MapPost("/transfer-completed", async (CompleteTransferDto request, IConfiguration config) =>
{
var apiKey = config["SendGrid:ApiKey"];
var fromEmail = config["SendGrid:FromEmail"];
var fromName = config["SendGrid:FromName"];
var toEmail = config["SendGrid:ToEmail"];
var toName = config["SendGrid:ToName"];
var client = new SendGridClient(apiKey);
var from = new EmailAddress(fromEmail, fromName);
var subject = "NCE Transfer Completed";
var to = new EmailAddress(toEmail, toName);
var htmlContent = $@"
<html>
<body>
<p>Team,</p>
<p>We would like to inform you that the NCE transfer process has been successfully completed. Please find the details below:</p>
<ul style='list-style-type:none; padding: 0;'>
<li><strong>Resource URI:</strong> {request.ResourceUri}</li>
<li><strong>Date of Change (UTC):</strong> {request.ResourceChangeUtcDate.ToString("u")}</li>
</ul>
<p>If you have any questions or need further assistance, please don’t hesitate to reach out.</p>
<p>Best regards,<br/>
<strong>Sherweb Support Team</strong>
</body>
</html>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, null, htmlContent);
try
{
//var smtpClient = new SmtpClient("smtp.gmail.com")
//{
// Port = 587,
// Credentials = new System.Net.NetworkCredential("[email protected]", "ylmsnhumxxnumurn"),
// EnableSsl = true,
//};
//var mailMessage = new MailMessage
//{
// From = new MailAddress("[email protected]", "Sherweb"),
// Subject = "NCE Transfer Completed",
// IsBodyHtml = true,
// Body = $@"
// <html>
// <body>
// <p>Team,</p>
// <p>We would like to inform you that the NCE transfer process has been successfully completed. Please find the details below:</p>
// <ul style='list-style-type:none; padding: 0;'>
// <li><strong>Resource URI:</strong> {request.ResourceUri}</li>
// <li><strong>Date of Change (UTC):</strong> {request.ResourceChangeUtcDate.ToString("u")}</li>
// </ul>
// <p>If you have any questions or need further assistance, please don’t hesitate to reach out.</p>
// <p>Best regards,<br/>
// <strong>Sherweb Support Team</strong>
// </body>
// </html>"
//};
//mailMessage.To.Add("[email protected]");
//await smtpClient.SendMailAsync(mailMessage);
return Results.Ok("Request received.");
var response = await client.SendEmailAsync(msg);
return response.IsSuccessStatusCode ? Results.Ok("Email sent successfully.") : Results.Problem("Error sending email.");
}
catch (Exception ex)
{
Expand Down
1 change: 1 addition & 0 deletions Xtkl.NceTransferWebhooks/Xtkl.NceTransferWebhooks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.7" />
<PackageReference Include="SendGrid" Version="9.29.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

Expand Down

0 comments on commit b826e7b

Please sign in to comment.