Skip to content

Commit

Permalink
Merge pull request #108 from DoWhile-UOM/dev
Browse files Browse the repository at this point in the history
Fix email issue
  • Loading branch information
Isuranga-2001 authored Jun 12, 2024
2 parents 076c514 + a7bf42e commit b9c9a99
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
9 changes: 3 additions & 6 deletions FirstStep/Services/EmailSevices/EmailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
using FirstStep.Data;
using FirstStep.Models;
using FirstStep.Models.DTOs;
using FirstStep.Template;
using Microsoft.EntityFrameworkCore;
using MimeKit;
using System.Threading;
using System.Resources;

namespace FirstStep.Services
{
Expand Down Expand Up @@ -107,11 +108,7 @@ public async Task<string> SendOTPEmail(VerifyEmailDto request) //Send OTP to the
{
var builder = new BodyBuilder();

using (StreamReader SourceReader = File.OpenText("././Template/CommonOTPEmailTemplate.html"))
{
builder.HtmlBody = SourceReader.ReadToEnd();
}

builder.HtmlBody = EmailTemplates.CommonOTP;
otpBody.To = request.email;
otpBody.Subject = "FirstStep Verification OTP";
builder.HtmlBody = builder.HtmlBody.Replace("{OTP}", OTPrequest.otp.ToString());
Expand Down
49 changes: 49 additions & 0 deletions FirstStep/Template/EmailTemplates.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace FirstStep.Template
{
public static class EmailTemplates
{
public static string CommonOTP =
@"
<!DOCTYPE html>
<html>
<head>
<meta charset=""utf-8"" />
<title>Verify Your Email</title>
</head>
<body>
<div style=""font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px;"">
<h2 style=""color: #333;"">FirstStep</h2>
<h3 style=""color: #333;"">Hello {name}!</h3>
<h3 style=""color: #333;"">Verify your Email</h3>
<p>Below is your one-time password. Use that code to verify your email {message}.</p>
<div style=""background-color: #f4f4f4; padding: 10px; border-radius: 5px;"">
<h2 style=""font-size: 22px; color: #333; margin: 0;"">OTP Code:</h2>
<p style=""font-size: 20px; color: #333; margin: 10px 0;""><strong>{OTP}</strong></p>
</div>
<p style=""color: #333; margin-top: 20px;"">- FirstStep</p>
</div>
</body>
</html>";

public static string ApplicationSentEmail =
@"<!DOCTYPE html>
<html>
<head>
<meta charset=""utf-8"" />
<title>Verify Your Email</title>
</head>
<body>
<div style=""font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px;"">
<h2 style=""color: #333;"">FirstStep</h2>
<div style=""background-color: #f4f4f4; padding: 10px; border-radius: 5px;"">
<h3 style=""color: #333;"">Hi {username}</h3>
<p>Your Application has been successfully sent.</p>
</div>
<p style=""color: #333; margin-top: 20px;"">- FirstStep</p>
</div>
</body>
</html>";
}
}

0 comments on commit b9c9a99

Please sign in to comment.