Send Email with .Net Framework.
Simple usage.
n/a
Use nuget package to install
Install-Package MentosMail
To use instace one server 'SmtpServer'
MentosMail.SmtpServer serverEmail = new MentosMail.SmtpServer(GetConfigSmtp());
serverEmail.Send(GetMessage());
static MentosMail.SmtpServerConf GetConfigSmtp()
{
return new MentosMail.SmtpServerConf
{
Host = "smtp.gmail.com",
Username = "email@gmail.com",
Password = "your-password",
Port = 465,
UseDefaultCredential = false,
UseSsl = true
};
}
static MessageMail GetMessage()
static MentosMail.MessageBox.MessageMail GetMessage()
{
var msgBuilder = new MentosMail.MessageBox.MessageMailBuilder()
.To(new MailAddress("to@email.com","to display name"))
.BodyMessage(GenerateTemplate()) //send text
.Subject("Subject Email")
.Encoding(Encoding.UTF8)
.IsBodyHtml()
.Priority(MailPriority.High)
.ReplyTo(new MailAddress("reply@email.com","name for display"))
.Sender(new MailAddress("sender@email.com","sender display name"));
return msgBuilder.Build();
}
And also support models with attributes to mark the sending by email facilitating the substitution of terms in a template
See the example below:
static string GenerateTemplate()
{
string htmlTemplate = @"<html>
<head></head>
<body>
<p> <strong>Name:</strong> <span>[Name]</span> </p>
<p> <strong>AnotherField</strong> <span>[(phone)]</span></p>
</body>
</html>";
var model = new ModelExample
{
AnotherField = "This is a field",
Name = "Guilherme Almeida (guigomesa)"
};
var templateService = new MentosMail.TemplateService(htmlTemplate);
return templateService.GenerateTemplateFromViewModel(model);
}
Check the "UsageExampleMentosMail" project to see it in action
In future support for sender servers (MailGun etc) and assync methods to send email.
- Send email assynchronous method (throw exception if invoke methods)
- Retrieve templates from file or url (throw exception if invoke methods)
@miltonfilho thanks for comments (: