using sib_api_v3_sdk.Api;
using sib_api_v3_sdk.Client;
using sib_api_v3_sdk.Model;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MisIngredientesVue.Core.Services
{
public interface IEmailService
{
void SendEmail(bool includeAds, string from, string[] to, string subject, string body, bool isBodyHtml = false, params MailAttachment[] attachments);
}
public class EmailService : IEmailService
{
public void SendEmail(bool includeAds, string from, string[] to, string subject, string body, bool isBodyHtml = false, params MailAttachment[] attachments)
{
//Console.WriteLine("----------------\n\n\n" + body);
//return;
if (to != null)
to = to.Where(x => x.Contains("@")).Select(x => x.ToLower().Trim()).ToArray();
var apiKey = "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";
// Configure API key authorization: api-key
Configuration.Default.AddApiKey("api-key", apiKey);
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.AddApiKeyPrefix("api-key", "Bearer");
// Configure API key authorization: partner-key
Configuration.Default.AddApiKey("partner-key", apiKey);
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.AddApiKeyPrefix("partner-key", "Bearer");
if (isBodyHtml && includeAds)
{
body += $@"
Este correo fue generado por Mis Ingredientes. Visite el sitio web para conocer más: https://misingredientes.mx
"; } var apiInstance = new SMTPApi(); var sendSmtpEmail = new SendSmtpEmail( new SendSmtpEmailSender("Mis Ingredientes", from), to.Select(x => new SendSmtpEmailTo(x)).ToList(), null, null, isBodyHtml ? body : null, isBodyHtml ? null : body, subject); if (attachments != null && attachments.Length > 0) { sendSmtpEmail.Attachment = new List