Files
Wino-Mail/Wino.Core/Services/UnsubscriptionService.cs

36 lines
1012 B
C#
Raw Normal View History

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Serilog;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Reader;
2025-02-16 11:54:23 +01:00
namespace Wino.Core.Services;
public class UnsubscriptionService : IUnsubscriptionService
{
2025-02-16 11:54:23 +01:00
public async Task<bool> OneClickUnsubscribeAsync(UnsubscribeInfo info)
{
2025-02-16 11:54:23 +01:00
try
{
2025-02-16 11:54:23 +01:00
using var httpClient = new HttpClient();
2025-02-16 11:54:23 +01:00
var unsubscribeRequest = new HttpRequestMessage(HttpMethod.Post, info.HttpLink)
{
2025-02-16 11:54:23 +01:00
Content = new StringContent("List-Unsubscribe=One-Click", Encoding.UTF8, "application/x-www-form-urlencoded")
};
2025-02-16 11:35:43 +01:00
2025-02-16 11:54:23 +01:00
var result = await httpClient.SendAsync(unsubscribeRequest).ConfigureAwait(false);
return result.IsSuccessStatusCode;
}
catch (Exception ex)
{
Log.Error("Failed to unsubscribe from {HttpLink} - {Message}", info.HttpLink, ex.Message);
}
2025-02-16 11:54:23 +01:00
return false;
}
}