1

Having trouble sending an email with FluentEmail using a Gmail server. When I run my code I get a System.AggregateException with a server response 5.7.0 Authentication Required.

I have tried turning allow less secure apps to ON in my Gmail settings but it still doesn't work. Have I not properly formatted the code or is this a google server issue?

namespace EmailDemo
{
    class Program
    {
        static async Task Main(string[] args)
        {
            SmtpClient smtp = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                UseDefaultCredentials = false,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                Credentials = new NetworkCredential("AGmailAccount@gmail.com", "AGmailPW")
            };

            Email.DefaultSender = new SmtpSender(smtp);
            var email = Email
              .From("GmailUser@gmail.com")
              .To("GmailReceiver@gmail.com")
              .Subject("Test Email")
              .Body("email content yes we love content YARRRR");
            
            var test = email.Send();
        }
    }
  • Hey, please check https://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not as your issue was there before – Luke Mar 01 '21 at 15:54
  • Does this answer your question? [Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required](https://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not) – Igor Goyda Mar 01 '21 at 19:29

1 Answers1

0

Try this

var smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    UseDefaultCredentials = false,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    Credentials = new NetworkCredential("ACCOUNTHERE", "PASSWORDHERE")
};

Email.DefaultSender = new SmtpSender(smtp);

var email = await Email
    .From("ACCOUNTHERE")
    .To("lina-ahmed@mail.com", "Lina")
    .Subject("Thanks!")
    .Body("Thanks for buying our product.")
    .SendAsync();
Mahmmoud Kinawy
  • 551
  • 4
  • 11