GithubHelp home page GithubHelp logo

jturinetti / mailer.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from romankalachik/mailer.net

0.0 1.0 0.0 1.2 MB

Biblioteca para auxiliar no envio de email, usando template com NVelocity e diferentes tipos de transport.

License: MIT License

C# 96.90% HTML 0.61% Batchfile 2.49%

mailer.net's Introduction

About

Mailer.NET is a library to help you to send emails. You can use templates and different transports like Mailgun and Smtp.

Install Mailer.NET via nuget

Install-Package Mailer.NET 

Add ConfigSection of Mailer.Net

  <configSections>
    <section name="mailernet" type="Mailer.NET.Mailer.Internal.ConfigFile.MailerNetSection, Mailer.NET, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" requirePermission="false" />
  </configSections>

Configure Mailer.NET to use smtp

Put the following snippet on your app.config or web.config

<mailernet>
    <defaultTransport type="Mailer.NET.Mailer.Transport.SmtpTransport, Mailer.NET">
      <parameters>
        <parameter value="host"/>
        <parameter value="port" type="System.Int32"/>
        <parameter value="user"/>
        <parameter value="password"/>
        <parameter value="useOrNotSsl" type="System.Boolean"/>
      </parameters>
    </defaultTransport>
  </mailernet>

Configure Mailer.NET to use Mailgun

Put the following snippet on your app.config or web.config

<mailernet>
    <defaultTransport type="Mailer.NET.Mailer.Transport.MailgunTransport, Mailer.NET">
      <parameters>
        <parameter value="damain"/>
        <parameter value="apikey"/>
      </parameters>
    </defaultTransport>
  </mailernet>

Send email with a simple message

Email email = new Email(EmailContentType.Text)
{
	From = new Contact() {Name = "sender", Email = "email_sender"}
};
email.AddTo("dest_email", "dest");
email.Subject = "subject";
email.Message = "simple message"
bool sent = email.Send();

Send email with template

Html template file should be locate in APP_DIR\Email\Template\template.html

Email email = new Email(EmailContentType.Html)
{
	From = new Contact() {Name = "sender", Email = "email_sender"}
};
email.AddTo("dest_email", "dest");
email.Subject = "subject";
email.Template = "template";
email.AddTemplateVar("person", "teste");
email.AddTemplateVar("number", "123");
bool sent = email.Send();

Template file

<html>
<head>
    <meta charset="utf-8" />
</head>
<body>
    <h4>Template Example</h4>
    <p>Hello $person, this is a example template</p>
</body>
</html>

the $person will be replaced to teste

Configure transport dinamically

MailgunTransport transport = new MailgunTransport("domain", "apikey");
Email email = new Email(transport,EmailContentType.Html)

How to add your custom transport

Create your class extending Mailer.NET.Transport.AbstractTransport and implement SendEmail method.

public class CustomTransport : AbstractTransport
{
    public override EmailResponse SendEmail(Email email)
    {
        //your logic to send email here
        return new EmailResponse("Message", true);
    }
}

mailer.net's People

Contributors

lira92 avatar ntfrex avatar jturinetti avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.