implementado emailer
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
VisualStudioVersion = 17.6.33829.357
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controladora", "Controladora\Controladora.csproj", "{7168B549-F229-4D49-8C53-AF1CEB9BBB6B}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{6C83A4AB-C70D-4D4E-A879-5E960C4A103A} = {6C83A4AB-C70D-4D4E-A879-5E960C4A103A}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entidades", "Entidades\Entidades.csproj", "{78A331E5-86D4-427E-AA45-5879F9E5E98B}"
|
||||
EndProject
|
||||
@@ -14,6 +17,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vista", "Vista\Vista.csproj
|
||||
{7168B549-F229-4D49-8C53-AF1CEB9BBB6B} = {7168B549-F229-4D49-8C53-AF1CEB9BBB6B}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Informes", "Informes\Informes.csproj", "{6C83A4AB-C70D-4D4E-A879-5E960C4A103A}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{78A331E5-86D4-427E-AA45-5879F9E5E98B} = {78A331E5-86D4-427E-AA45-5879F9E5E98B}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -36,6 +44,10 @@ Global
|
||||
{8C9E8090-5D8F-42AE-9813-C68D384C6863}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8C9E8090-5D8F-42AE-9813-C68D384C6863}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8C9E8090-5D8F-42AE-9813-C68D384C6863}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6C83A4AB-C70D-4D4E-A879-5E960C4A103A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6C83A4AB-C70D-4D4E-A879-5E960C4A103A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6C83A4AB-C70D-4D4E-A879-5E960C4A103A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6C83A4AB-C70D-4D4E-A879-5E960C4A103A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
10
Informes/ConfigEmail.cs
Normal file
10
Informes/ConfigEmail.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Informes
|
||||
{
|
||||
public class ConfigEmail
|
||||
{
|
||||
public string EmailAddr { get; set; }
|
||||
public string EmailPass { get; set; }
|
||||
public List<string> EmailTarget { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
133
Informes/InformeEmail.cs
Normal file
133
Informes/InformeEmail.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
using System.Diagnostics;
|
||||
using System.Net.Mail;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
|
||||
using Entidades;
|
||||
namespace Informes
|
||||
{
|
||||
public class InformeEmail
|
||||
{
|
||||
/// <summary>
|
||||
/// Envia Informes por Email
|
||||
/// </summary>
|
||||
|
||||
private static InformeEmail instance = new();
|
||||
public static InformeEmail Instance
|
||||
{
|
||||
get { return instance; }
|
||||
}
|
||||
|
||||
public string EnviarEmailFactura(string titulo, List<DetalleFactura> desc)
|
||||
{
|
||||
string? ret = null;
|
||||
string json;
|
||||
ConfigEmail config;
|
||||
try
|
||||
{ // leemos el archivo de configuracion para obtener los certificados y mails destino de los informes
|
||||
json = File.ReadAllText("settings.json");
|
||||
config = JsonSerializer.Deserialize<ConfigEmail>(json);
|
||||
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
ret = "No se pudo leer el archivo \"settings.json\"";
|
||||
throw;
|
||||
}
|
||||
|
||||
foreach (var i in config.EmailTarget)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(i)) return "Hay Emails mal cargados";
|
||||
|
||||
}
|
||||
|
||||
SmtpClient smtp = new SmtpClient();
|
||||
smtp.Host = "smtp.gmail.com";
|
||||
smtp.Port = 587;
|
||||
smtp.Credentials = new NetworkCredential(config.EmailAddr, config.EmailPass);
|
||||
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
smtp.EnableSsl = true;
|
||||
|
||||
MailMessage mail = new MailMessage();
|
||||
mail.Subject = titulo;
|
||||
mail.IsBodyHtml = true;
|
||||
mail.Body = GenerarTabla(desc);
|
||||
mail.Sender = new MailAddress(config.EmailAddr);
|
||||
foreach (var i in config.EmailTarget) mail.To.Add(i);
|
||||
mail.From = new MailAddress(config.EmailAddr);
|
||||
|
||||
try
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine($"From: {config.EmailAddr}, Title: {titulo}");
|
||||
#endif
|
||||
smtp.Send(mail);
|
||||
mail.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
ret = "No se pudo comunicar con el server SMTP";
|
||||
throw;
|
||||
}
|
||||
|
||||
//Decimos que se envio el email correctamente si el valor del retorno sigue siendo nulo en otro caso tendra la descripcion del error.
|
||||
return (ret == null) ?
|
||||
"Se envio el Email Correctamente":
|
||||
ret;
|
||||
//
|
||||
}
|
||||
|
||||
private string GenerarTabla(List<DetalleFactura> desc)
|
||||
{
|
||||
// Esta seccion es el armado del mail html
|
||||
string body =
|
||||
@"
|
||||
<style>
|
||||
table, td, th {
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Producto</td>
|
||||
<th>Cantidad</td>
|
||||
<th>Precio CU</td>
|
||||
<th>Subtotal</td>
|
||||
</tr>";
|
||||
|
||||
foreach (var i in desc)
|
||||
{
|
||||
body +=
|
||||
@$"
|
||||
<tr>
|
||||
<td>{i.Producto.Nombre}</td>
|
||||
<td>{i.Cantidad}</td>
|
||||
<td>{i.Producto.Precio}</td>
|
||||
<td>{i.Producto.Precio * i.Cantidad}</td>
|
||||
</tr>";
|
||||
}
|
||||
|
||||
body +=
|
||||
@$"
|
||||
<tr>
|
||||
<td>Total</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{CalcularTotal(desc)}</td>
|
||||
</tr>
|
||||
</table>
|
||||
";
|
||||
return body;
|
||||
}
|
||||
private double CalcularTotal(List<DetalleFactura> desc)
|
||||
{
|
||||
double total = 0;
|
||||
foreach (var i in desc)
|
||||
{
|
||||
total += i.Producto.Precio * i.Cantidad;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
13
Informes/Informes.csproj
Normal file
13
Informes/Informes.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Entidades\Entidades.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
|
||||
@@ -0,0 +1 @@
|
||||
55f9793ce92bee586e65f5b38a3a7676261de34c
|
||||
@@ -0,0 +1,11 @@
|
||||
is_global = true
|
||||
build_property.TargetFramework = net6.0
|
||||
build_property.TargetPlatformMinVersion =
|
||||
build_property.UsingMicrosoftNETSdkWeb =
|
||||
build_property.ProjectTypeGuids =
|
||||
build_property.InvariantGlobalization =
|
||||
build_property.PlatformNeutralAssembly =
|
||||
build_property.EnforceExtendedAnalyzerRules =
|
||||
build_property._SupportedPlatformList = Linux,macOS,Windows
|
||||
build_property.RootNamespace = Informes
|
||||
build_property.ProjectDir = C:\Users\fedpo\Downloads\Final\Final\Informes\
|
||||
8
Informes/obj/Debug/net6.0/Informes.GlobalUsings.g.cs
Normal file
8
Informes/obj/Debug/net6.0/Informes.GlobalUsings.g.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
// <auto-generated/>
|
||||
global using global::System;
|
||||
global using global::System.Collections.Generic;
|
||||
global using global::System.IO;
|
||||
global using global::System.Linq;
|
||||
global using global::System.Net.Http;
|
||||
global using global::System.Threading;
|
||||
global using global::System.Threading.Tasks;
|
||||
BIN
Informes/obj/Debug/net6.0/Informes.assets.cache
Normal file
BIN
Informes/obj/Debug/net6.0/Informes.assets.cache
Normal file
Binary file not shown.
Binary file not shown.
124
Informes/obj/Informes.csproj.nuget.dgspec.json
Normal file
124
Informes/obj/Informes.csproj.nuget.dgspec.json
Normal file
@@ -0,0 +1,124 @@
|
||||
{
|
||||
"format": 1,
|
||||
"restore": {
|
||||
"C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj": {}
|
||||
},
|
||||
"projects": {
|
||||
"C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj",
|
||||
"projectName": "Entidades",
|
||||
"projectPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj",
|
||||
"packagesPath": "C:\\Users\\fedpo\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\fedpo\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net6.0"
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"https://api.nuget.org/v3/index.json": {},
|
||||
"https://fedesrv.ddns.net/git/api/packages/fede/nuget/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.306\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj",
|
||||
"projectName": "Informes",
|
||||
"projectPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj",
|
||||
"packagesPath": "C:\\Users\\fedpo\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\fedpo\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net6.0"
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"https://api.nuget.org/v3/index.json": {},
|
||||
"https://fedesrv.ddns.net/git/api/packages/fede/nuget/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"projectReferences": {
|
||||
"C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj": {
|
||||
"projectPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.306\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Informes/obj/Informes.csproj.nuget.g.props
Normal file
15
Informes/obj/Informes.csproj.nuget.g.props
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
|
||||
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
||||
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\fedpo\.nuget\packages\</NuGetPackageFolders>
|
||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.6.0</NuGetToolVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<SourceRoot Include="C:\Users\fedpo\.nuget\packages\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
2
Informes/obj/Informes.csproj.nuget.g.targets
Normal file
2
Informes/obj/Informes.csproj.nuget.g.targets
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
|
||||
92
Informes/obj/project.assets.json
Normal file
92
Informes/obj/project.assets.json
Normal file
@@ -0,0 +1,92 @@
|
||||
{
|
||||
"version": 3,
|
||||
"targets": {
|
||||
"net6.0": {
|
||||
"Entidades/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETCoreApp,Version=v6.0",
|
||||
"compile": {
|
||||
"bin/placeholder/Entidades.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"bin/placeholder/Entidades.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"Entidades/1.0.0": {
|
||||
"type": "project",
|
||||
"path": "../Entidades/Entidades.csproj",
|
||||
"msbuildProject": "../Entidades/Entidades.csproj"
|
||||
}
|
||||
},
|
||||
"projectFileDependencyGroups": {
|
||||
"net6.0": [
|
||||
"Entidades >= 1.0.0"
|
||||
]
|
||||
},
|
||||
"packageFolders": {
|
||||
"C:\\Users\\fedpo\\.nuget\\packages\\": {}
|
||||
},
|
||||
"project": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj",
|
||||
"projectName": "Informes",
|
||||
"projectPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj",
|
||||
"packagesPath": "C:\\Users\\fedpo\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\fedpo\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net6.0"
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"https://api.nuget.org/v3/index.json": {},
|
||||
"https://fedesrv.ddns.net/git/api/packages/fede/nuget/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"projectReferences": {
|
||||
"C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj": {
|
||||
"projectPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.306\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Informes/obj/project.nuget.cache
Normal file
8
Informes/obj/project.nuget.cache
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "0ffqkIvM7yuJgCFn+/y+/ChgFN4B08rK4q2o0qfR2mjDbPa/G9BYCj14N+kvE/m1MgKnQvlnSGf4GAaYLGJr8w==",
|
||||
"success": true,
|
||||
"projectFilePath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj",
|
||||
"expectedPackageFiles": [],
|
||||
"logs": []
|
||||
}
|
||||
Reference in New Issue
Block a user