using System;
using System.Net;
using System.Net.Mail;
using FluentEmail.Core;
using FluentEmail.Smtp;
// https://github.com/lukencode/FluentEmail
// https://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not
// Checkout...
// MailKit - support SSL, crytography, authentication
// Papercut-SMTP - for testing, mocking, pretend SMTP server, etc
namespace TopNugetPackages
{
public class MainFluentEmailDriver
{
private string FromEmail = "zaken520@gmail.com";
private string FromEmailPassword = "SECRET";
private string ToEmail = "";
// easily send an email
public void DoIt()
{
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
UseDefaultCredentials = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(FromEmail, FromEmailPassword)
};
Email.DefaultSender = new SmtpSender(smtp);
var email = Email
.From(FromEmail)
.To(ToEmail)
.Subject("Test Email Subject Line")
.Body("HELLO WORLD");
var resp = email.Send();
if (resp.Successful)
{
Console.WriteLine($"Send Successful: {resp.MessageId}");
}
else
{
Console.WriteLine($"Send Failed: {resp.ErrorMessages}");
}
}
}
}