71

I need to send email via my C# app.

I come from a VB 6 background and had a lot of bad experiences with the MAPI control. First of all, MAPI did not support HTML emails and second, all the emails were sent to my default mail outbox. So I still needed to click on send receive.

If I needed to send bulk html bodied emails (100 - 200), what would be the best way to do this in C#?

16 Answers 16

97

You could use the System.Net.Mail.MailMessage class of the .NET framework.

You can find the MSDN documentation here.

Here is a simple example (code snippet):

using System.Net;
using System.Net.Mail;
using System.Net.Mime;

...
try
{

   SmtpClient mySmtpClient = new SmtpClient("my.smtp.exampleserver.net");

    // set smtp-client with basicAuthentication
    mySmtpClient.UseDefaultCredentials = false;
   System.Net.NetworkCredential basicAuthenticationInfo = new
      System.Net.NetworkCredential("username", "password");
   mySmtpClient.Credentials = basicAuthenticationInfo;

   // add from,to mailaddresses
   MailAddress from = new MailAddress("[email protected]", "TestFromName");
   MailAddress to = new MailAddress("[email protected]", "TestToName");
   MailMessage myMail = new System.Net.Mail.MailMessage(from, to);

   // add ReplyTo
   MailAddress replyTo = new MailAddress("[email protected]");
   myMail.ReplyToList.Add(replyTo);

   // set subject and encoding
   myMail.Subject = "Test message";
   myMail.SubjectEncoding = System.Text.Encoding.UTF8;

   // set body-message and encoding
   myMail.Body = "<b>Test Mail</b><br>using <b>HTML</b>.";
   myMail.BodyEncoding = System.Text.Encoding.UTF8;
   // text or html
   myMail.IsBodyHtml = true;

   mySmtpClient.Send(myMail);
}

catch (SmtpException ex)
{
  throw new ApplicationException
    ("SmtpException has occured: " + ex.Message);
}
catch (Exception ex)
{
   throw ex;
}
5
  • 2
    What alternatives are there to embedding passwords directly into the code? Commented Jun 15, 2009 at 23:58
  • 7
    The NetworkCredential class is overloaded. If you provide an empty constructor, it will create the instance with the current user. Alternatively, you could also encrypt the username and password and store it externally. It also depends on how you set up your mail server. You can set up an SMTP server on the localhost and allow it to be a relay for the loopback address, so that you can send email without credentials. We do the latter. It is lightweight, simple, and requires no storing of passwords (since anyone can relay from the loopback address - meaning IIS can, as well). Commented Nov 6, 2009 at 12:13
  • 4
    You can also configure all that with <system.net><mailSettings> in your config file. I use this all the time to send mail to a directory while developing, then switch it to send for real when ready to go live.
    – dotjoe
    Commented May 6, 2010 at 19:56
  • 1
    The replyTo attribute is deprecated, now you have to use myMail.ReplyToList.Add(replyTo); which allows multiple reply addresses. You can also pull attributes from the config file with ConfigurationManager.appSettings["replyTo"] if you have them set like this: <configuration> <appSettings> <add key="replyTo" value="[email protected]"/> </appSettings> </configuration>
    – CSS
    Commented Sep 4, 2015 at 18:41
  • 3
    Important notes from MSDN:<br/> - The SmtpClient class has no Finalize method, so an application must call Dispose to explicitly free up resources. - The SmtpClient type is now obsolete. We don't recommend that you use the SmtpClient class for new development because SmtpClient doesn't support many modern protocols. Commented Apr 9, 2021 at 9:12
15

Code:

using System.Net.Mail

new SmtpClient("smtp.server.com", 25).send("[email protected]", 
                                           "[email protected]", 
                                           "subject", 
                                           "body");

Mass Emails:

SMTP servers usually have a limit on the number of connection hat can handle at once, if you try to send hundreds of emails you application may appear unresponsive.

Solutions:

  • If you are building a WinForm then use a BackgroundWorker to process the queue.
  • If you are using IIS SMTP server or a SMTP server that has an outbox folder then you can use SmtpClient().PickupDirectoryLocation = "c:/smtp/outboxFolder"; This will keep your system responsive.
  • If you are not using a local SMTP server than you could build a system service to use Filewatcher to monitor a forlder than will then process any emails you drop in there.
1
  • 3
    For my simple purposes your answer worked well. Two lines of code rather than 20!
    – MrVimes
    Commented Apr 9, 2014 at 19:56
15

The best way to send bulk emails for more faster way is to use threads.I have written this console application for sending bulk emails.I have seperated the bulk email ID into two batches by creating two thread pools.

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Net.Mail;

namespace ConsoleApplication1
{
    public class SendMail 
    {
        string[] NameArray = new string[10] { "Recipient 1", 
                                              "Recipient 2",
                                              "Recipient 3",
                                              "Recipient 4", 
                                              "Recipient 5", 
                                              "Recipient 6", 
                                              "Recipient 7", 
                                              "Recipient 8",
                                              "Recipient 9",
                                              "Recipient 10"
                                            };        

        public SendMail(int i, ManualResetEvent doneEvent)
        {
            Console.WriteLine("Started sending mail process for {0} - ", NameArray[i].ToString() + " at " + System.DateTime.Now.ToString());
            Console.WriteLine("");
            SmtpClient mailClient = new SmtpClient();
            mailClient.Host = Your host name;
            mailClient.UseDefaultCredentials = true;
            mailClient.Port = Your mail server port number; // try with default port no.25

            MailMessage mailMessage = new MailMessage(FromAddress,ToAddress);//replace the address value
            mailMessage.Subject = "Testing Bulk mail application";
            mailMessage.Body = NameArray[i].ToString();
            mailMessage.IsBodyHtml = true;
            mailClient.Send(mailMessage);
            Console.WriteLine("Mail Sent succesfully for {0} - ",NameArray[i].ToString() + " at " + System.DateTime.Now.ToString());
            Console.WriteLine("");

            _doneEvent = doneEvent;
        }

        public void ThreadPoolCallback(Object threadContext)
        {
            int threadIndex = (int)threadContext;
            Console.WriteLine("Thread process completed for {0} ...",threadIndex.ToString() + "at" +  System.DateTime.Now.ToString());
            _doneEvent.Set();
        }      

        private ManualResetEvent _doneEvent;
    }


    public class Program
    {
        static int TotalMailCount, Mailcount, AddCount, Counter, i, AssignI;  
        static void Main(string[] args)
        {
            TotalMailCount = 10;
            Mailcount = TotalMailCount / 2;
            AddCount = Mailcount;
            InitiateThreads();                     

            Thread.Sleep(100000);
        }

       static void InitiateThreads()
       {
            //One event is used for sending mails for each person email id as batch
           ManualResetEvent[] doneEvents = new ManualResetEvent[Mailcount];

            // Configure and launch threads using ThreadPool:
            Console.WriteLine("Launching thread Pool tasks...");

            for (i = AssignI; i < Mailcount; i++)            
            {
                doneEvents[i] = new ManualResetEvent(false);
                SendMail SRM_mail = new SendMail(i, doneEvents[i]);
                ThreadPool.QueueUserWorkItem(SRM_mail.ThreadPoolCallback, i);
            }

            Thread.Sleep(10000);

            // Wait for all threads in pool to calculation...
            //try
            //{
            // //   WaitHandle.WaitAll(doneEvents);
            //}
            //catch(Exception e)
            //{
            //    Console.WriteLine(e.ToString());   
            //}

            Console.WriteLine("All mails are sent in this thread pool.");
            Counter = Counter+1;
            Console.WriteLine("Please wait while we check for the next thread pool queue");
            Thread.Sleep(5000);
            CheckBatchMailProcess();            
        }

        static  void CheckBatchMailProcess()
        {

            if (Counter < 2)
            {
                Mailcount = Mailcount + AddCount;
                AssignI = Mailcount - AddCount;
                Console.WriteLine("Starting the Next thread Pool");

                Thread.Sleep(5000);
                InitiateThreads();
            }

            else
            {
                Console.WriteLine("No thread pools to start - exiting the batch mail application");
                Thread.Sleep(1000);
                Environment.Exit(0);
            }
        }
    }   
}

I have defined 10 recepients in the array list for a sample.It will create two batches of emails to create two thread pools to send mails.You can pick the details from your database also.

You can use this code by copying and pasting it in a console application.(Replacing the program.cs file).Then the application is ready to use.

I hope this helps you :).

0
12

April 2023 update:

The recommended library is now Mailkit.

using MailKit.Net.Smtp;
using MimeKit;

var message = new MimeMessage();
message.From.Add(new MailboxAddress(name: "John Doe", address: "[email protected]"));
message.To.Add(new MailboxAddress(name: "Bruce Williams", address: "[email protected]"));
message.Subject = "Test subject";

message.Body = new TextPart("plain")
{
    Text = "Test body"
};

using (var client = new SmtpClient())
{
    client.Connect(host: "mail.inbox.example", port: 587, useSsl: true);
    client.Authenticate(userName: "test", password: "test");
    client.Send(message);
    client.Disconnect(quit: true);
}

System.Net.Mail.SmtpClient is not recommended by .NET authors.

MailKit's authors also say that:

For SMTP, most developers use System.Net.Mail.SmtpClient which suits their needs more-or-less satisfactorily and so is probably not high on their list of needs. However, the SmtpClient implementation included with MailKit is a much better option if cross-platform support is needed or if the developer wants to be able to save and re-load MIME messages before sending them via SMTP. MailKit's SmtpClient also supports PIPELINING which should improve performance of sending messages (although might not be very noticeable).

4

The .NET framework has some built-in classes which allows you to send e-mail via your app.

You should take a look in the System.Net.Mail namespace, where you'll find the MailMessage and SmtpClient classes. You can set the BodyFormat of the MailMessage class to MailFormat.Html.

It could also be helpfull if you make use of the AlternateViews property of the MailMessage class, so that you can provide a plain-text version of your mail, so that it can be read by clients that do not support HTML.

http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.alternateviews.aspx

2
  • :) how is the order of answers defined ? A while ago splattne's answer was the 3rd one, now it's the first one ... Think I should read the FAQ ;) (first time around here) Commented Jan 16, 2009 at 9:08
  • First the accepted answer, below that all others ranked by votes
    – edosoft
    Commented Jan 16, 2009 at 10:29
4

You can send email using SMTP or CDO

using SMTP:

mail.From = new MailAddress("[email protected]");
mail.To.Add("to_address");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";

SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;

using CDO

CDO.Message oMsg = new CDO.Message();
CDO.IConfiguration iConfg;
iConfg = oMsg.Configuration;
ADODB.Fields oFields;
oFields = iConfg.Fields;
ADODB.Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
oFields.Update();
oMsg.Subject = "Test CDO";
oMsg.From = "from_address";
oMsg.To = "to_address";
oMsg.TextBody = "CDO Mail test";
oMsg.Send();

Source : C# SMTP Email

Source: C# CDO Email

3

I can strongly recommend the aspNetEmail library: http://www.aspnetemail.com/

The System.Net.Mail will get you somewhere if your needs are only basic, but if you run into trouble, please check out aspNetEmail. It has saved me a bunch of time, and I know of other develoeprs who also swear by it!

1
  • This is a commercial product where you will need a license. Commented Sep 26, 2017 at 7:38
2
   public string sendEmail(string mail,string subject, string body)
   {
       try
       {
           MailMessage message = new MailMessage();
           SmtpClient smtp = new SmtpClient();
           message.From = new MailAddress("[email protected]");
           message.To.Add(new MailAddress(mail));
           message.Subject = subject;
           message.IsBodyHtml = true; //to make message body as html  
           message.Body = body;
           smtp.Port = 587;
           smtp.Host = "smtp.gmail.com"; //for gmail host  
           smtp.EnableSsl = true;
           smtp.UseDefaultCredentials = false;
           smtp.Credentials = new NetworkCredential("[email protected]", "password");
           smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
           smtp.Send(message);
           return "success";
       }
       catch (Exception e) {
           return e.Message;
       }
   }‏
1

Use the namespace System.Net.Mail. Here is a link to the MSDN page

You can send emails using SmtpClient class.

I paraphrased the code sample, so checkout MSDNfor details.

MailMessage message = new MailMessage(
   "[email protected]",
   "[email protected]",
   "Subject goes here",
   "Body goes here");

SmtpClient client = new SmtpClient(server);
client.Send(message);

The best way to send many emails would be to put something like this in forloop and send away!

1
  • 2
    Don't forget "message.IsBodyHtml = true" before sending. Commented Jan 16, 2009 at 9:02
1

Take a look at the FluentEmail library. I've blogged about it here

You have a nice and fluent api for your needs:

Email.FromDefault()
 .To("[email protected]")
 .Subject("New order has arrived!")
 .Body("The order details are…")  
 .Send();
1

Let's make something as a full solution :). Maybe it can help as well. It is a solution for sending one email content and one attach file (or without attach) to many Email addresses. Of course sending just one email is possibility as well. Result is List object with data what is OK and what is not.

namespace SmtpSendingEmialMessage
{ 
    public class EmailSetupData
    {
        public string EmailFrom { get; set; }
        public string EmailUserName { get; set; }
        public string EmailPassword { get; set; }
        public string EmailSmtpServerName { get; set; }
        public int EmailSmtpPortNumber { get; set; }
        public Boolean SSLActive { get; set; } = false;
    }

    public class SendingResultData
    {
        public string SendingEmailAddress { get; set; }
        public string SendingEmailSubject { get; set; }
        public DateTime SendingDateTime { get; set; }
        public Boolean SendingEmailSuccess { get; set; }
        public string SendingEmailMessage { get; set; }
    }
    public class OneRecData
    {
        public string RecEmailAddress { get; set; } = "";
        public string RecEmailSubject { get; set; } = "";
    }


    public class SendingProcess
    {
        public string EmailCommonSubjectOptional { get; set; } = "";
        private EmailSetupData EmailSetupParam { get; set; }
        private List<OneRecData> RecDataList { get; set; }
        private string EmailBodyContent { get; set; }
        private Boolean IsEmailBodyHtml { get; set; }
        private string EmailAttachFilePath { get; set; }

        public SendingProcess(List<OneRecData> MyRecDataList, String MyEmailTextContent, String MyEmailAttachFilePath, EmailSetupData MyEmailSetupParam, Boolean EmailBodyHtml)
        {
            RecDataList = MyRecDataList;
            EmailBodyContent = MyEmailTextContent;
            EmailAttachFilePath = MyEmailAttachFilePath;
            EmailSetupParam = MyEmailSetupParam;
            IsEmailBodyHtml = EmailBodyHtml;
        }

        public List<SendingResultData> SendAll()
        {
            List<SendingResultData> MyResList = new List<SendingResultData>();
            foreach (var js in RecDataList)
            {
                using (System.Net.Mail.MailMessage MyMes = new System.Net.Mail.MailMessage())
                {
                    DateTime SadaJe = DateTime.Now;
                    Boolean IsOK = true;
                    String MySendingResultMessage = "Sending OK";

                    String MessageSubject = EmailCommonSubjectOptional;
                    if (MessageSubject == "")
                    {
                        MessageSubject = js.RecEmailSubject;
                    }

                    try
                    {

                        System.Net.Mail.MailAddress MySenderAdd = new System.Net.Mail.MailAddress(js.RecEmailAddress);
                        MyMes.To.Add(MySenderAdd);
                        MyMes.Subject = MessageSubject;
                        MyMes.Body = EmailBodyContent;
                        MyMes.Sender = new System.Net.Mail.MailAddress(EmailSetupParam.EmailFrom);
                        MyMes.ReplyToList.Add(MySenderAdd);
                        MyMes.IsBodyHtml = IsEmailBodyHtml;

                    }
                    catch(Exception ex)
                    {
                        IsOK = false;
                        MySendingResultMessage ="Sender or receiver Email address error." +  ex.Message;
                    }

                    if (IsOK == true)
                    {
                        try
                        {
                            if (EmailAttachFilePath != null)
                            {
                                if (EmailAttachFilePath.Length > 5)
                                {
                                    MyMes.Attachments.Add(new System.Net.Mail.Attachment(EmailAttachFilePath));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            IsOK = false;
                            MySendingResultMessage ="Emial attach error. " +  ex.Message;
                        }

                        if (IsOK == true)
                        {
                            using (System.Net.Mail.SmtpClient MyCl = new System.Net.Mail.SmtpClient())
                            {
                                MyCl.EnableSsl = EmailSetupParam.SSLActive;
                                MyCl.Host = EmailSetupParam.EmailSmtpServerName;
                                MyCl.Port = EmailSetupParam.EmailSmtpPortNumber;
                                try
                                {
                                    MyCl.Credentials = new System.Net.NetworkCredential(EmailSetupParam.EmailUserName, EmailSetupParam.EmailPassword);
                                }
                                catch (Exception ex)
                                {
                                    IsOK = false;
                                    MySendingResultMessage = "Emial credential error. " + ex.Message;
                                }

                                if (IsOK == true)
                                {
                                    try
                                    {
                                        MyCl.Send(MyMes);
                                    }
                                    catch (Exception ex)
                                    {
                                        IsOK = false;
                                        MySendingResultMessage = "Emial sending error. " + ex.Message;
                                    }
                                }
                            }
                        }
                    }

                    MyResList.Add(new SendingResultData
                    {
                            SendingDateTime = SadaJe,
                            SendingEmailAddress = js.RecEmailAddress,
                            SendingEmailMessage = MySendingResultMessage,
                            SendingEmailSubject = js.RecEmailSubject,
                            SendingEmailSuccess = IsOK
                    });
                }

            }
            return MyResList;
        }
    }

}
1
using System.Net.Mail;

using (MailMessage mail = new MailMessage())
{
    mail.From = new MailAddress("your email address");
    mail.To.Add("to...email address");
    mail.Subject = "mail subject";
    mail.IsBodyHtml = true;
    mail.Body = "mail body (you can write html here)";

    using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
    {
        smtp.Credentials = new System.Net.NetworkCredential("your email address", "app password");
        smtp.EnableSsl = true;
        smtp.Send(mail);
    }
}

to send email using C# you can use this code with smtp (it's a server for Gmail is a free Send mail server) but instead of "app password" you must make an app pass from your email account (if you enter your email account password it does not work because of google Security policies)

to make app password:
1.go to manage your account
2.security
3.enable 2 step verification
4.search app password
5.generate app password
6.use sixteen character app password in C# code above

0

You can use Mailkit. MailKit is an Open Source cross-platform .NET mail-client library that is based on MimeKit and optimized for mobile devices.

It has more and advance features better than System.Net.Mail

  • A fully-cancellable Pop3Client with support for STLS, UIDL, APOP, PIPELINING, UTF8, and LANG. Client-side sorting and threading of messages (the Ordinal Subject and the Jamie Zawinski threading algorithms are supported).
  • Asynchronous versions of all methods that hit the network.
  • S/MIME, OpenPGP and DKIM signature support via MimeKit.
  • Microsoft TNEF support via MimeKit.

See this example you can send mail

            MimeMessage mailMessage = new MimeMessage();
            mailMessage.From.Add(new MailboxAddress(senderName, [email protected]));
            mailMessage.Sender = new MailboxAddress(senderName, [email protected]);
            mailMessage.To.Add(new MailboxAddress(emailid, emailid));
            mailMessage.Subject = subject;
            mailMessage.ReplyTo.Add(new MailboxAddress(replyToAddress));
            mailMessage.Subject = subject;
            var builder = new BodyBuilder();
            builder.TextBody = "Hello There";            
            try
            {
                using (var smtpClient = new SmtpClient())
                {
                    smtpClient.Connect("HostName", "Port", MailKit.Security.SecureSocketOptions.None);
                    smtpClient.Authenticate("[email protected]", "password");

                    smtpClient.Send(mailMessage);
                    Console.WriteLine("Success");
                }
            }
            catch (SmtpCommandException ex)
            {
                Console.WriteLine(ex.ToString());              
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());                
            }

You can download from here.

0

Below the attached solution work over local machine and server.

     public static string SendMail(string bodyContent)
    {
        string sendMail = "";
        try
        {

            string fromEmail = "[email protected]";
            MailMessage mailMessage = new MailMessage(fromEmail, "[email protected]", "Subject", body);
            mailMessage.IsBodyHtml = true;
            SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
            smtpClient.EnableSsl = true;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials = new NetworkCredential(fromEmail, frompassword);
            smtpClient.Send(mailMessage);
        }
        catch (Exception ex)
        {
            sendMail = ex.Message.ToString();
            Console.WriteLine(ex.ToString());
        }
        return sendMail;
    }
0

To not make your data exposed and right procedure set them in the appsetting

using MailKit.Net.Smtp;
using Microsoft.EntityFrameworkCore;
using MimeKit;

namespace Admin.Services
{
    public class EmailService
    {
        private readonly string _from;
        private readonly string _host;
        private readonly int _port;
        private readonly string _smtpUser;
        private readonly string _smtpPassword;
        private readonly IHttpContextAccessor _contextAccessor;
        private readonly Context _Context;
        private readonly PassResetByEmailService _passResetByEmailService;
        public EmailService(
            Context Context,
            IConfiguration configuration,
            IHttpContextAccessor contextAccessor,
            PassResetByEmailService passResetByEmailService
            )
        {
            _from = configuration["EmailConfig:From"];
            _host = configuration["EmailConfig:Host"];
            _port = int.Parse(configuration["EmailConfig:Port"]);
            _smtpUser = configuration["EmailConfig:UserName"];
            _smtpPassword = configuration["EmailConfig:Password"];
            _passResetByEmailService = passResetByEmailService;
            _Context = Context;
            _contextAccessor = contextAccessor;
        }

  

        public async Task<string?> SendPassEmail(string email)
        {
        //Check email nel DB 
        var remail = await _grabcadContext.UTENTE.FirstOrDefaultAsync(c => c.EMAIL == email && !c.FLG_DISABILITATO && !c.FLG_ELIMINATO);
        if (remail == null)
            return "Email non trovata";

        var request = _contextAccessor.HttpContext.Request;
        var requestUrl = $"{request.Scheme}://{request.Host}{request.PathBase}";
        var resetPasswordUrl = $"{requestUrl}/Account/ResetPasswordToken";

        var token = await _passResetByEmailService.AddPassResetByEmailService(email);

        var subject = "Reset password";
        var content = $"link: {resetPasswordUrl}?email={email}&token={token}";

        using (var client = new SmtpClient())
        {
            try
            {
                var emailMessage = new MimeMessage();
                emailMessage.From.Add(new MailboxAddress(_from, _from));
                emailMessage.To.Add(new MailboxAddress(email, email));
                emailMessage.Subject = subject;
                emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Text) { Text = content };


                await client.ConnectAsync(_host, _port, true);
                client.AuthenticationMechanisms.Remove("XOAUTH2");
                await client.AuthenticateAsync(_smtpUser, _smtpPassword);
                await client.SendAsync(emailMessage);
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                await client.DisconnectAsync(true);
                client.Dispose();
            }
        }
        return null;
    }
  }
}

appsettings.json

   
  "SysAdminEmail": "[email protected] ",
  "HostPort": {
    "Port": 587,
    "Host": "smtp.com"
  }
}

0

Another more easy way without libraries

var smtpClient = new SmtpClient("smtp.gmail.com")
{
    Port = 587,
    Credentials = new NetworkCredential("username", "password"),
    EnableSsl = true,
};
    
smtpClient.Send("[email protected]", "[email protected]", "Payment notification", "100 dollars");


Note: According to this, SmtpClient should not be used but if you can't use a library like MailKit, SmtpClient works for simple scenarios


If you don't have a real mail for your localhost tests, you could use a smtp mock server like mailcatcher

docker run -d -p 1025:1025 -p 1080:1080 haravich/fake-smtp-server:1.0.1

Then the parameters to send a mail will be:

var smtpClient = new SmtpClient("localhost")
{
    Port = 1025,
    Credentials = new NetworkCredential("whatever", "whatever"),
    EnableSsl = false,
};
    
smtpClient.Send("[email protected]", "[email protected]", "Payment notification", "100 dollars");

You could see the mail opening http://localhost:1080

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.