.Net C# Development

Sending Email

public void SendEmail(string receiver, string subject, string message)
        {
            try
            {

                var senderEmail = new MailAddress("noreply@delma-exchange.com", "Delma Exchange");
                var receiverEmail = new MailAddress(receiver, "Client");
                var password = "******";
                var sub = subject;
                var body = message;
                var smtp = new SmtpClient
                {
                    Host = "smtp.office365.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(senderEmail.Address, password)
                };
                using (var mess = new MailMessage(senderEmail, receiverEmail)
                {
                    Subject = subject,
                    Body = body
                })
                {
                   // Add a carbon copy recipient.
                    MailAddress copy = new MailAddress("Notification_List@abc.com");
                    mess.CC.Add(copy);
                    smtp.Send(mess);
              }

            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

        }

Leave a Reply

Your email address will not be published. Required fields are marked *