GenericEmailService 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package GenericEmailService --version 1.0.0
NuGet\Install-Package GenericEmailService -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GenericEmailService" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GenericEmailService --version 1.0.0
#r "nuget: GenericEmailService, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GenericEmailService as a Cake Addin
#addin nuget:?package=GenericEmailService&version=1.0.0

// Install GenericEmailService as a Cake Tool
#tool nuget:?package=GenericEmailService&version=1.0.0

Dependency

This library was created by .Net 7.0

Install

dotnet add package GenericEmailService --version 1.0.0

Use

SendEmailModel sendEmailModel = new(
    List<string> emails, 
    string email, 
    string password,
    string subject, 
    string body, 
    string smtp, 
    bool html,
    bool ssl, 
    int port, 
    List<Attachment>? attachments
)
await EmailService.SendEmailAsync(sendEmailModel);

Methods

This library have one methods and one class.

invoke

    public sealed class SendEmailModel
    {
        public SendEmailModel()
        {

        }
        public SendEmailModel(List<string> emails, string email, string password,string subject, string body, string smtp, bool html,bool ssl, int port, List<Attachment>? attachments)
        {
            Emails = emails;
            Email = email;
            Subject = subject;
            Body = body;
            Html = html;
            Smtp = smtp;
            Password = password;
            SSL = ssl;
            Port = port;
            Attachments = attachments;
        }

        public List<string> Emails { get; set; }
        public string Email { get; set; }
        public string Subject { get; set; }
        public string Body { get; set; }
        public bool Html { get; set; }
        public string Smtp { get; set; }
        public string Password { get; set; }
        public bool SSL { get; set; }
        public int Port { get; set; }
        public List<Attachment>? Attachments { get; set; }
    } 
    public static class EmailService
    {        
        public static async Task SendEmailAsync(SendEmailModel sendEmailModel)
        {            
            using (MailMessage mail = new MailMessage())
            {                
                mail.From = new MailAddress(sendEmailModel.Email);
                foreach (var email in sendEmailModel.Emails)
                {
                    mail.To.Add(email);
                }
                mail.Subject = sendEmailModel.Subject;
                mail.Body = sendEmailModel.Body;
                mail.IsBodyHtml = sendEmailModel.Html;
                if(sendEmailModel.Attachments != null)
                {
                    foreach (var attachment in sendEmailModel.Attachments)
                    {
                        mail.Attachments.Add(attachment);
                    }
                }                
                using (SmtpClient smtp = new SmtpClient(sendEmailModel.Smtp))
                {
                    smtp.UseDefaultCredentials = false;
                    smtp.Credentials = new NetworkCredential(sendEmailModel.Email, sendEmailModel.Password);
                    smtp.EnableSsl = sendEmailModel.SSL;
                    smtp.Port = sendEmailModel.Port;
                    await smtp.SendMailAsync(mail);
                }
            }
        }
    }
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 134 8/7/2023
1.0.1 139 8/7/2023
1.0.0 325 1/15/2023