mirror of
https://github.com/fergalmoran/podnoms.git
synced 2025-12-22 09:18:08 +00:00
Merge tag 'v0.18' into develop
Added email handling and scheduled youtube update job
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pod-noms.web",
|
"name": "pod-noms.web",
|
||||||
"version": "0.17.0",
|
"version": "0.18.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
|
|||||||
7
server/Services/IMailSender.cs
Normal file
7
server/Services/IMailSender.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PodNoms.Api.Services {
|
||||||
|
public interface IMailSender {
|
||||||
|
Task<bool> SendEmail(string email, string subject, string message);
|
||||||
|
}
|
||||||
|
}
|
||||||
46
server/Services/MailgunSender.cs
Normal file
46
server/Services/MailgunSender.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using PodNoms.Api.Models;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace PodNoms.Api.Services {
|
||||||
|
public class MailgunSender : IMailSender {
|
||||||
|
private readonly EmailSettings _emailSettings;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
public MailgunSender(IOptions<EmailSettings> emailSettings, ILogger<MailgunSender> logger){
|
||||||
|
_emailSettings = emailSettings.Value;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> SendEmail(string email, string subject, string message){
|
||||||
|
using (var client = new HttpClient { BaseAddress = new Uri(_emailSettings.ApiBaseUri) }) {
|
||||||
|
client.DefaultRequestHeaders.Authorization =
|
||||||
|
new AuthenticationHeaderValue("Basic",
|
||||||
|
Convert.ToBase64String(Encoding.ASCII.GetBytes(_emailSettings.ApiKey)));
|
||||||
|
|
||||||
|
_logger.LogInformation($"From: {_emailSettings.From}\nTo: {email}\nApi key: {_emailSettings.ApiKey}");
|
||||||
|
|
||||||
|
var content = new FormUrlEncodedContent(new[]
|
||||||
|
{
|
||||||
|
new KeyValuePair<string, string>("from", _emailSettings.From),
|
||||||
|
new KeyValuePair<string, string>("to", email),
|
||||||
|
new KeyValuePair<string, string>("subject", subject),
|
||||||
|
new KeyValuePair<string, string>("html", message)
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = await client.PostAsync(_emailSettings.RequestUri, content).ConfigureAwait(false);
|
||||||
|
if (result.StatusCode == HttpStatusCode.OK)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
_logger.LogError($"Error {result.StatusCode} sending mail\n{result.ReasonPhrase}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -156,7 +156,7 @@ namespace PodNoms.Api {
|
|||||||
services.AddScoped<IUserRepository, UserRepository>();
|
services.AddScoped<IUserRepository, UserRepository>();
|
||||||
services.AddScoped<IUrlProcessService, UrlProcessService>();
|
services.AddScoped<IUrlProcessService, UrlProcessService>();
|
||||||
services.AddScoped<IAudioUploadProcessService, AudioUploadProcessService>();
|
services.AddScoped<IAudioUploadProcessService, AudioUploadProcessService>();
|
||||||
services.AddScoped<IMailSender, MailSender>();
|
services.AddScoped<IMailSender, MailgunSender>();
|
||||||
|
|
||||||
services.AddSingleton(typeof(HubLifetimeManager<DebugHub>),
|
services.AddSingleton(typeof(HubLifetimeManager<DebugHub>),
|
||||||
typeof(DebugHubLifetimeManager<DebugHub>));
|
typeof(DebugHubLifetimeManager<DebugHub>));
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"App": {
|
"App": {
|
||||||
"Version": "0.17.0",
|
"Version": "0.18.0",
|
||||||
"RssUrl": "http://localhost:5000/rss/"
|
"RssUrl": "http://localhost:5000/rss/"
|
||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
|
|||||||
Reference in New Issue
Block a user