-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#126) adding email service to infrastructure
- Loading branch information
1 parent
471c0ec
commit 9acba8b
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...e.Services.Email/src/MiniSpace.Services.Email.Infrastructure/Services/SmtpEmailService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Net.Mail; | ||
using System.Net; | ||
using MiniSpace.Services.Email.Application.Services; | ||
|
||
namespace MiniSpace.Services.Email.Infrastructure.Services | ||
{ | ||
public class SmtpEmailService : IEmailService | ||
{ | ||
private readonly string _smtpHost; | ||
private readonly int _smtpPort; | ||
private readonly string _fromEmail; | ||
private readonly string _password; | ||
private readonly bool _enableSSL; | ||
|
||
public SmtpEmailService(string smtpHost, int smtpPort, string fromEmail, string password, bool enableSSL) | ||
{ | ||
_smtpHost = smtpHost; | ||
_smtpPort = smtpPort; | ||
_fromEmail = fromEmail; | ||
_password = password; | ||
_enableSSL = enableSSL; | ||
} | ||
|
||
public async Task SendEmailAsync(string to, string subject, string body) | ||
{ | ||
var mailMessage = new MailMessage(_fromEmail, to, subject, body); | ||
using (var client = new SmtpClient(_smtpHost, _smtpPort)) | ||
{ | ||
client.EnableSsl = _enableSSL; | ||
client.Credentials = new NetworkCredential(_fromEmail, _password); | ||
await client.SendMailAsync(mailMessage); | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...Space.Services.Email/src/MiniSpace.Services.Email.Infrastructure/Services/SmtpSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace MiniSpace.Services.Email.Infrastructure.Services | ||
{ | ||
public class SmtpSettings | ||
{ | ||
public string Host { get; set; } | ||
public int Port { get; set; } | ||
public string Username { get; set; } | ||
public string Password { get; set; } | ||
public bool EnableSSL { get; set; } | ||
} | ||
} |